Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 31st, 2012  |  syntax: None  |  size: 0.96 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. RestEasy @EJB returning null
  2. @Path("/")
  3. public class Service extends Application{
  4. @EJB
  5. private GlobalStore store;
  6. public Service(){
  7. fromejbstore = store.getSentiment();//null pointer is thrown
  8. }
  9. }
  10.        
  11. @Singleton
  12. @Startup
  13. public class GlobalStore {
  14.  Sentiment sentiment;
  15.  @PostConstruct
  16. public void initialize() {
  17.  //do something
  18. }
  19. public Sentiment getSentiment(){return sentiment;}
  20. }
  21.        
  22. @ApplicationPath("/rest")
  23. public class JaxRsActivator extends Application {
  24.  /* class body intentionally left blank */
  25. }
  26.        
  27. @Path("/test")
  28. public class Service
  29. {
  30.   @EJB private GlobalStore store;
  31.  
  32.   @GET @Path("/test")
  33.   public String getTime()
  34.   {
  35.    boolean test = (store==null);
  36.    return "Test: "+test;
  37.   }
  38. }
  39.        
  40. `try{
  41.         InitialContext ctx=new InitialContext();
  42.         localRef = (myEjb) ctx.lookup("java:global/appName/EjbName");
  43.        }catch(NamingException ne){
  44.             System.out.println("n[MyRestService]NamingException: "+ne);
  45.             ne.printStackTrace();
  46.        }`