jQuery in Action, 2nd edition*
The moose likes EJB and other Java EE Technologies and the fly likes Dependency INjection through Annotations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Dependency INjection through Annotations" Watch "Dependency INjection through Annotations" New topic
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: 30136
    
150

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: 9955
    
163

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dependency INjection through Annotations
 
Similar Threads
EJB3 @EJB annotation not loading Session bean
Call EJB from Application Client
jndi name in ejb3?
Can't access EJB from remote client
Getting Class cast exception while Lookup EJB2.1 session bean using JNDI name in WAS6.1