Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RestEasy+EJB in JBoss 7, here @Inject throws Null Pointer Exception

 
Sachin Pachari
Ranch Hand
Posts: 56
Eclipse IDE Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,

i am new to this whole web service, i am stuck with this JAXRS(RestEasy) project where i have to integrate my EJB with the Service and i am not able to @Inject or @EJB, everytime i try to inject, i get a Null Pointer Exeption, i have been Searching in google to solve this issue,

i have tried all the possible solutions. like adding @Stateless, adding Beans.xml to my META-INF and also configuring RestEasy CDI Injector Factory in my Web.xml

But no use, i am using JBoss AS 7.0, i keep on getting null pointer, is it even possible to inject any object into my (JAX-RS) Web Services ?? Someone please help me, i have been stuck in this point for more than a week. Someone Please Explain me clearly about this.

Any Kind of help is welcome.

Thanks & Regards,
Sachin
 
timo erler
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maybe the following works for you

web.xml


MyApplication.java


MyResource.java is a RootResource which injetcs a Singleton-Bean containing an EntityManager.




This works for me as long as i do not work with subclasses



MySubResource injects the Singleton-Bean. Now I get the NullpointerException again.

Anyone an idea?
 
timo erler
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i solved the problem with subresources...

my resource is a bean
my subresource is a bean

so is use the following code to get my subresource-bean



all in all it was an stupid mistake, because beans are beans and managed by container ;)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic