Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Dependency Injection for referenced class does not work

843830Oct 9 2009 — edited Oct 12 2009
Hey guys,

I hope you can help. Following scenario, description below:

JPAServiceLocal.java:
@Local
public interface JPAServiceLocal
{
...
}
WebServiceBean.java:
@Stateless
public class WebServiceBean
{

   @EJB
   JPAServiceLocal jpa; //this Dependency Injection WORKS, I can work with the jpa object
   ...

public void serviceMethod1(){

   jpa.method(); //WORKS

   ControllerBean controller = new ControllerBean();
   controller.doSomething();
}
ControllerBean.java:
@Stateless
public class ControllerBean

   @EJB
   JPAServiceLocal jpa; //this Dependency Injection DOES NOT WORK
   
   public void doSomething(){
   
      jpa.method(); //*NullPointerException*
   }
   
The (stateless) Session Bean WebServiceBean uses another (stateless) Session Bean ControllerBean as a helper class. Dependency Injection works for the first, but not for the second bean. But why? The ControllerBean is not a POJO, it runs within the same EAR and therefore JVM, so all requirements are fulfilled, right?!

My ejb-jar.xml is empty, do I have to put something in there?

My application server is SAP NetWeaver 7.11.

Thanks for any hint, do I understand something wrong?

Cheers

Tim
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 9 2009
Added on Oct 9 2009
9 comments
298 views