This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Web Services and the fly likes RestEasy+EJB in JBoss 7, here @Inject throws Null Pointer Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "RestEasy+EJB in JBoss 7, here @Inject throws Null Pointer Exception" Watch "RestEasy+EJB in JBoss 7, here @Inject throws Null Pointer Exception" New topic
Author

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

Sachin Pachari
Ranch Hand

Joined: Jan 16, 2012
Posts: 56

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

Joined: Dec 04, 2012
Posts: 2
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

Joined: Dec 04, 2012
Posts: 2
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 ;)
 
jQuery in Action, 2nd edition
 
subject: RestEasy+EJB in JBoss 7, here @Inject throws Null Pointer Exception
 
Similar Threads
@inject annotation throwing null pointer exception in Restful web service project
Calling a web service from an session bean.
Asynchronous web service using RESTEasy
REST Web Service - Dynamic Query Parameters
How to write a RESTful web service with Eclipse tutorial that assumes very little?