| Author |
Dependency Injection not working?
|
vShyam Sundar
Ranch Hand
Joined: Oct 13, 2010
Posts: 59
|
|
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: 8208
|
|
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: 59
|
|
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: 8208
|
|
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: 59
|
|
Thanks for your valuable reply
|
 |
 |
|
|
subject: Dependency Injection not working?
|
|
|