Reputation: 381
I have a project and i am trying to inject my service, but i keep getting null pointer exception injecting the UserService. And i cannot figure out what i am missing.
I added the project to my github, https://github.com/JohnnyBekkestad/demo, mind you that in order to focus on the problem i removed a lot of code to clean it up.
If anyone can see what i am missing i would gratefully appreciate it.
Best Regards Johnny
Upvotes: 0
Views: 102
Reputation: 365
Check out this tutorial if using Tomcat and remember to add beans.xml, to change web.xml and incluce / exclude the not necessary dependencies (weld). Furthermore there is no such annotation pair
@Path
@ManagedBean
Remember: JAX-RS (or in your case Jersey) tells you, when it finds any implementation, which means @Path is enough:
INFO: Root resource classes found:
class com.bekkestad.demo.web.rest.UserController
And as a starter: Tomcat is no Java EE container. If using GlassFish 4 then get comfortable with Java EE first (@EJB > @Stateless) then add CDI capability - but then you do not have to add any dependencies since weld is already available (= no context.xml or changes in web.xml needed, just a beans.xml in WEB-INF and also in all other projects META-INF directories).
Upvotes: 0
Reputation: 11733
Your WAR
file is missing a beans.xml
file here: https://github.com/JohnnyBekkestad/demo/tree/master/web/rest/src/main/webapp/WEB-INF
Assuming that you're trying to inject the service here and this is where the NPE Is coming from:
Upvotes: 2