
Untitled
By: a guest on
Jul 31st, 2012 | syntax:
None | size: 0.96 KB | hits: 15 | expires: Never
RestEasy @EJB returning null
@Path("/")
public class Service extends Application{
@EJB
private GlobalStore store;
public Service(){
fromejbstore = store.getSentiment();//null pointer is thrown
}
}
@Singleton
@Startup
public class GlobalStore {
Sentiment sentiment;
@PostConstruct
public void initialize() {
//do something
}
public Sentiment getSentiment(){return sentiment;}
}
@ApplicationPath("/rest")
public class JaxRsActivator extends Application {
/* class body intentionally left blank */
}
@Path("/test")
public class Service
{
@EJB private GlobalStore store;
@GET @Path("/test")
public String getTime()
{
boolean test = (store==null);
return "Test: "+test;
}
}
`try{
InitialContext ctx=new InitialContext();
localRef = (myEjb) ctx.lookup("java:global/appName/EjbName");
}catch(NamingException ne){
System.out.println("n[MyRestService]NamingException: "+ne);
ne.printStackTrace();
}`