This week's book giveaway is in the Open Source forum.
We're giving away four copies of Programmers Guide to Apache Thrift and have Randy Abernethy on-line!
See this thread for details.
Win a copy of Programmers Guide to Apache Thrift this week in the Open Source forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Dependency INjection through Annotations  RSS feed

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have an EJB Module project which has:




And below is the web module:


But i am getting the bewlo exception:
Starting...
java.lang.NullPointerException
at com.stateless.DepInjHelloWorld.main(DepInjHelloWorld.java:19)


Line 19:System.out.println(hello.getMessage("Using Annotations Instead Of JNDI LookUp"));

PLease tell me if i need to configure anywhere,as i am not using any xml file.

Regards,
Amarshi
 
author & internet detective
Posts: 39281
727
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not a web module; it is a main method. Are you running it as an application client or a regular Java class? If the later, you need to do a JNDI lookup and not dependency injection.
 
amarshi mohanty
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have also tried using a servlet instead of the standalone class, but the same exception comes.


---Amarshi
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amrish,

Hope this help
This is Stand Alone Client for EJB 3.0 in JBoss :
 
amarshi mohanty
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks pulkit, i have tried this way its working.
But i want to use dependency injection instead of jndi lookup.
I have googled a couple of examples (using dependency injection for jndi look up instead of using initial context for lookup), but for me the business interface instance comes as null.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You actually have 2 questions here.

1) Injection into standalone java clients - This isn't possible unless you use an application client container. See this previous discussion

2) Injection into servlets - This is allowed. If you are not able to inject into servlet, then see if the issue is related to this
 
pulkit mehra
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See..according to my experience dependency injection gets failed due to following reason :

1)You are using server which does not support DI in web container.eg JBoss 4.x(DI work in EJB not in WEB)
2)You must have giving wrong JNDI name.Please refer to JNDI console of your server and see naming convention they follow.
 
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!