[jboss-user] [EJB 3.0] - Re: circular references

robert.geisler do-not-reply at jboss.com
Mon Jun 29 11:08:02 EDT 2009


you are always very fast, jaikiran :)
god bless you ; )


"jaikiran" wrote : 
  | As far as i know, it's not possible to do this at class level.
  | 
to do what at class level? to @IgnoreDependency?

"jaikiran" wrote : 
  | Can you please provide a bit more details about the issue you are running into? Preferably with the relevant code and the logs.
  | 
our problem is, that we do not want to use dependency injection on some stateless beans, because we want to lazy lookup a few ejbs just when we really use them. earlier we achieved that through private getters that looked up the ejbs by their local jndi name (@LocalBinding). but we cannot use this pattern anymore, because we want our .ear to be portable to WebSphereAS (WAS doesnt have such a thing like @LocalBinding, but requires a "ejblocal:/" prefix for local business interfaces).
thats why we put class level @EJBs annotation on that stateless beans and use getters that lookup the ejbs by the logical name declared in @EJB.
we thought this way we may avoid injection of ejbs that mostly never will get used. but when we now deploy our .ear on JBoss, JBoss complains about circular references (as we would use dependency injection).

please have a look at the simplified code below.

here is one statless bean that declares dependency on class level. it dont use injection, but lazy lookup the referenced ejb through getter-method.
@Stateless(name = "StatlessOne")
  | @Local(value = StatlessOne.class)
  | @EJBs(value = { //
  |     @EJB(name = "StatlessTwo", beanName = "StatlessTwo", beanInterface = StatlessTwo.class)
  | })
  | public class StatlessOneBean implements StatlessOne {
  |   @Resource
  |   private SessionContext sessionContext;
  | 
  |   // lookup "on-demand"
  |   public StatlessTwo getStatlessTwo() {
  |     return (StatlessTwo) sessionContext.lookup("java:comp/env/" + "StatlessTwo";
  |   }
  | 
  |   ...
  |   
  | }
here is the corresponding ejb. the first ejb gets injected, beause the second one will always use the first ejb.
@Stateless(name = "StatlessTwo")
  | @Local(value = StatlessTwo.class)
  | public class StatlessTwoBean implements StatlessTwo {
  |   @Resource
  |   private SessionContext sessionContext;
  | 
  |   @EJB(beanName = "StatlessOne") // lookup "always"
  |   private StatlessOne statlessOne;
  | 
  |   public boolean hasStatlessOne() {
  |     return (statlessOne != null);
  |   }
  | 
  |   ...
  |   
  | }
and thats the errors, JBoss loggs when we deploy our .ear:
2009-06-29 13:23:15,054 INFO  [org.jboss.ejb3.EJB3Deployer] Starting java:comp multiplexer
  | ...
  | // all ejbs got deployed without errors:
  | INFO  [org.jboss.ejb3.EJB3Deployer] Deployed: file:/...MyServer.ear-contents/StatelessOne.jar
  | INFO  [org.jboss.ejb3.EJB3Deployer] Deployed: file:/...MyServer.ear-contents/StatelessTwo.jar
  | ...
  | INFO  [org.jboss.deployment.EARDeployer] Started J2EE application: file:/...MyServer.ear
  | // AFTER deployment these erros are shown:
  | ERROR [org.jboss.deployment.scanner.URLDeploymentScanner] Incomplete Deployment listing:
  | 
  | --- MBeans waiting for other MBeans ---
  | ObjectName: jboss.j2ee:ear=MyServer.ear,jar=StatelessTwo.jar,name=StatelessTwo,service=EJB3
  |   State: NOTYETINSTALLED
  |   I Depend On:
  |     jboss.j2ee:ear=AfpsServer.ear,jar=StatelessOne.jar,name=StatelessOne,service=EJB3
  | 
  | ObjectName: jboss.j2ee:ear=MyServer.ear,jar=StatelessOne.jar,name=StatelessOne,service=EJB3
  |   State: NOTYETINSTALLED
  |   I Depend On:
  |     jboss.j2ee:ear=MyServer.ear,jar=StatelessTwo.jar,name=StatelessTwo,service=EJB3
  | 
  | ...
  | 
  | INFO  [org.jboss.system.server.Server] JBoss (MX MicroKernel) [4.2.2.GA [...] Started [...]

maybe i missunterstood the @EJB annotation at all?
i thought, that * @EJB on class level just declares a dependency and the application server puts the corresponding ejb into the local jndi context, while * @EJB on field level injects an instance of the corresponding ejb into the fieldam i wrong?


regards robert



ps:
its complicated for me to explain all these things in english.
so i hope you will forgive me if i confuse you O: )


View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4240786#4240786

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4240786



More information about the jboss-user mailing list