Juni 1st, 2006

@EJB Bean Injection

Posted by frank in Java, J2EE

Mit Hilfe der Annotation @EJB können andere SessionBeans in SessionBeans oder MessageDrivenBeans genutzt werden und es entfällt der lästige JNDI-Lookup. Im Detail sieht dies dann so aus:

public class SessionBean1 implements Session1 {
  @EJB private Session2 session2;

  public void doSomething() {
    session2.fooBar();
  }
}

Wenn jetzt jedoch von SessionBean2 auf SessionBean1 auch zugegriffen wird, kann das Ganze aufgrund von Abhängigkeitsproblemen nicht deployed werden. Abhilfe schafft im JBoss (ab Version 4.0.4 GA) hier @IgnoreDependency.

import javax.annotation.EJB;
import org.jboss.annotation.IgnoreDependency;

public class SessionBean2 implements Session2 {
  @EJB
  @IgnoreDependency
  private Session1 session1;

  public void fooBar() {
    System.out.println(“foobar”);
  }

  public void aMethod() {
    session1.doSomething();
  }
}

No Responses to ' @EJB Bean Injection '

Subscribe to comments with RSS or TrackBack to ' @EJB Bean Injection '.

Leave a reply

:mrgreen: :neutral: :twisted: :shock: :smile: :???: :cool: :evil: :grin: :oops: :razz: :roll: :wink: :cry: :eek: :lol: :mad: :sad: