I just ran into a deployment error when deploying two stateless session beans each with dependency to the other and using @Inject.
@Stateless
class BeanA {
@Inject
BeanB b;
public void doSomething() {
b.doSomething();
}
}
@Stateless
class BeanB {
@Inject
BeanA a;
public void doSomeOtherThing() {
a.doSomeOtherThing();
}
}
When deploying this, I get this exception from Glassfish / weld:
org.jboss.weld.exceptions.DeploymentException: WELD-001443 Pseudo scoped bean has circular dependencies.
Injecting the Beans with @EJB instead of @Inject, everything works fine. Now I have two questions.
First - what happens inside weld that this won't be allowed?
Second (probably more important) - is this bad practice on architectural side and if yes do you know any patterns to avoid it? From my current knowledge was that business driven services on the same layer are allowed to communicate with each other in any way they need.