wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Dependency Injection not working? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Dependency Injection not working?" Watch "Dependency Injection not working?" New topic
Author

Dependency Injection not working?

vShyam Sundar
Ranch Hand

Joined: Oct 13, 2010
Posts: 60
Hi all,
Dependency Injection in EJB3 is allowed only on manageable classes? What is meant by this?
I tried to execute program with JNDI lookup and same With Dependency Injection. Unfortunately the code with Dependency Injection doesn't work. When i tried to execute the program with DI. I got a null pointer exception

I have pasted the code below. Please provide your valuable inputs


and my business interface is:.


and stateless bean code is as follows:


The above code executed well but when i changed the action servlet to achieve dependency injection, I got the null pointer exception.




Thanks,
Shyam.
Murali Ranga
Ranch Hand

Joined: Dec 16, 2011
Posts: 38

jndi name is missing to annotation.
@Stateless(name="CalculatorBean", mappedName="Sample1/CalculatorBean/remote")

Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9343
    
111

Do you have a web.xml? What does it look like? The xsd version declaration should be 2.5 or 3.0 for injection to work.

[My Blog] [JavaRanch Journal]
vShyam Sundar
Ranch Hand

Joined: Oct 13, 2010
Posts: 60
Thanks JaiKiran. It worked now. Previously i just had <web-app> tag in web.xml but now i replaced with

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"
version="2.5">

Any idea on why we need this extra attributes?

and also Dependency Injection is allowed only on managable classes- What is meant by this?

Thanks,
Shyam.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9343
    
111

vShyam Sundar wrote:
Any idea on why we need this extra attributes?

That's because prior to web-app version 2.5, dependency injection wasn't available.

vShyam Sundar wrote:
and also Dependency Injection is allowed only on managable classes- What is meant by this?



It means that dependency injection is supported on classes whose lifecycle is managed by the container(s). For example the servlets, EJBs etc...
vShyam Sundar
Ranch Hand

Joined: Oct 13, 2010
Posts: 60
Thanks for your valuable reply
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dependency Injection not working?
 
Similar Threads
Learning EJB3 on JBOSS 4.22
Could not access Local Session Bean using JNDI lookup
jndi name in ejb3?
Can't access EJB from remote client
Problem in JNDI look up in ejb 3.0