• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@Resource annotation question

 
Saathvik Reddy
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using @Resource annotation for injecting the data source as below:

But, I get a Null Pointer Exception.

If i do a JNDI look up like this it works



What am i doing wrong with injecting the data source?

Thanks,
Srikanth.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which version of JBoss and Java do you use? And where are you injecting this resource?
 
Saathvik Reddy
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jaikiran Pai:
Which version of JBoss and Java do you use? And where are you injecting this resource?


I am using JBoss 4.2.3GA with java 6. I am trying to inject the resource in a servlet at class level.
[ December 04, 2008: Message edited by: Srikanth Reddy ]
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does your web.xml look like? Have you used the web-app 2.5 xsd in the web.xml?
 
Saathvik Reddy
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jaikiran Pai:
What does your web.xml look like? Have you used the web-app 2.5 xsd in the web.xml?


Is it mandatory to use web-app 2.5 xsd? Also do i need to add <resource-ref> element in the web.xml?
[ December 04, 2008: Message edited by: Srikanth Reddy ]
 
Saathvik Reddy
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jaikiran Pai:
What does your web.xml look like? Have you used the web-app 2.5 xsd in the web.xml?


Jaikiran,

Here is how my web.xml looks like:


I am trying to inject the resource in servlet as:


Do i need to add resource-ref element in web.xml?

Thanks,
Srikanth.
[ December 04, 2008: Message edited by: Srikanth Reddy ]
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No you don't need a resource-ref in the web.xml
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:



Assuming that you are deploying a -ds.xml file to bind the OracleDS.
 
Saathvik Reddy
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jaikiran Pai:
Try this:



Assuming that you are deploying a -ds.xml file to bind the OracleDS.


Jaikiran,

I already did what you said with no luck. I spent whole day on this issue but didn't get any solutions.

Today i downloaded JBoss 5.0.0GA amazingly the same code worked!

I thought @resource annotations work in JBoss 4.2.3 but now i think they only work with JBoss 5.x versions. Is that correct?

Thanks,
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Srikanth Reddy:
Jaikiran,

I already did what you said with no luck. I spent whole day on this issue but didn't get any solutions.

Today i downloaded JBoss 5.0.0GA amazingly the same code worked!

I thought @resource annotations work in JBoss 4.2.3 but now i think they only work with JBoss 5.x versions. Is that correct?



I did know that @EJB injection would not work in JBoss-4.2.x, but i thought the @Resource would work. Infact, i think i even had an example on my previous machine with JBoss-4.2.3 where it had worked (if i remember correct). Once i get my new machine setup properly, let me give this a try.

Good to know, it worked with JBoss-5 GA which got released today.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic