| Author |
Dependency INjection through Annotations
|
amarshi mohanty
Ranch Hand
Joined: Jul 01, 2008
Posts: 110
|
|
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
|
SCJP (97%), SCWCD (95%))
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26173
|
|
|
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.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
amarshi mohanty
Ranch Hand
Joined: Jul 01, 2008
Posts: 110
|
|
I have also tried using a servlet instead of the standalone class, but the same exception comes.
---Amarshi
|
 |
pulkit mehra
Greenhorn
Joined: Jun 05, 2008
Posts: 12
|
|
Hi Amrish,
Hope this help
This is Stand Alone Client for EJB 3.0 in JBoss :
|
 |
amarshi mohanty
Ranch Hand
Joined: Jul 01, 2008
Posts: 110
|
|
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.
|
 |
Jaikiran Pai
Marshal
Joined: Jul 20, 2005
Posts: 8142
|
|
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
|
[My Blog] [JavaRanch Journal]
|
 |
pulkit mehra
Greenhorn
Joined: Jun 05, 2008
Posts: 12
|
|
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.
|
 |
 |
|
|
subject: Dependency INjection through Annotations
|
|
|