2 Replies Latest reply on May 31, 2011 2:47 AM by nimo22

    circular reference error

    nimo22

      I have two standard ejb-stateless-bean:




      @Stateless
      public class B1 {
      
      @In B2 b2;
      
      }



      @Stateless
      public class B2 {
      
      @In B1 b1;
      
      }




      You see, I inject one stateless bean to the other stateless bean, and vice versa.


      I get this error:
      org.jboss.weld.exceptions.DeploymentException: WELD-001443 Pseudo scoped bean has circular dependencies.


      Normally, circular dependencies are not a good design, but I need methods from B1 in B2 and methods from B2 in B1, what is wrong with that design?



        • 1. Re: circular reference error
          asiandub

          Well, the beans in your scenario are pseudo-scoped, this means that the container is unable to proxy them - which in turn leads to the deployment error.


          I can't give you technical details about why this exception is thrown, would be interesting to test if it would work if you use pure @EJB annotations for dependency injection.


          A workaround would be to change the scope to something proxyable like @RequestScoped...


          Cheers,
          Jan


          • 2. Re: circular reference error
            nimo22

            Yes, I did it before with @EJB and it works. A stateless EJB does not need/have a scope. When using @In, I also inject the scope and the STATE of the other bean, so I guess, this is the reason, why I have to assign a scope explicitly.


            However, it is much better to use @EJB in such scenarios - I only want to use the services and not want to hold some state/scope.


            thanks!