I'm trying to access an EJB Stateless session bean from a local service. But when I call a method that is located on the bean, I get a NPE because the stateless bean is null.
Here is the code:
The sateless bean:
@Startup
@Stateless(name = "LoginBean")
@LocalBean
public class LoginBean {
public List<Long> getItemsForClient(String clientId, Long itemId) {
System.out.println("clientID: " + clientId);
System.out.println("itemID: " + itemId);
List<Long> ret = new ArrayList<Long>();
ret.add((long) 123456);
ret.add((long) 123457);
ret.add((long) 123458);
ret.add((long) 123459);
return ret;
}
}
The service:
@Stateless
@Path("/ctofservice")
public class CtoFService {
@EJB
LoginBean loginBean;
public CtoFService() {
}
@GET
@Produces("text/plain")
@Path("test")
public String convertCtoF() {
Long l = (long) 123456;
List<Long> servicesForClient = LoginBean.getItemsForClient("cliID", l);
return itemsForClient.toString();
}
And the ApplicationConfig:
@ApplicationPath("/")
public class ApplicationConfig extends Application {
@SuppressWarnings("unchecked")
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new java.util.HashSet<Class<?>>();
addRestResourceClasses(resources);
return resources;
}
private void addRestResourceClasses(Set<Class<?>> resources) {
resources.add(CtoFService.class);
resources.add(uy.com.cns.services.beans.LoginBean.class);
}
}
I've been trying for a while and looking for possible solutions, but nothing came up.
I'm using JBoss AS 7.1 and RESTEasy that cames with it.
When the bean should get instantiated?
Thanks.
Aucun commentaire:
Enregistrer un commentaire