• Post Reply Bookmark Topic Watch Topic
  • New Topic

Injecting JMSContext result in NullpointerException

 
Yue Shen
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys

I am currently using glassfish 4.1 and JMS 2.0 for a project. I tried to inject JMSContext into a Servlet but it always returns null for context.



I even tried to specify the connection factory directly



I checked the Glassfish console and the above connection factory was created. Am I missing something?

Thanks!
 
Rob Spoor
Sheriff
Posts: 20837
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a guess, but have you tried @Resource instead of @Inject? Some things, like EJBContext, SessionContext, TimerService and DataSource, but also a lot of JMS stuff, should not be injected using @Inject but using @Resource instead.

I'm also guessing that JMSConnectionFactory does not need the additional @Inject or @Resource similarly to @PersistenceContext, and that the other annotation is actually causing the failed injection.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!