In my Java EE project, there are several "Java EE" modules and a web module. One of the Java EE modules provides a class to CDI that is to be used by the other modules:
@ApplicationScoped
public class XFactory {
@Produces @Actual
public X create() {
return new X();
}
}
They are injected into
@SessionScoped
public class Target implements Serializable {
X x;
@Inject
public void setX(@Actual X x){
this.x = x;
}
}
However, this works only in one of the Java EE modules and in the web module. In all of the remaining Java EE modules, injection consistently fails, and I am clueless as to why: All I get is WELD-1408, unsatisfied dependency.
All of the modules have beans.xml
in the proper places, they all work as long as I don't switch to injection. Most of the target beans are already in use as injected beans in a JSF.
What's special about the Java EE module that works is that the bean is injected into a servlet in the web module, not the JSF.
The project runs with Java EE 6, EJB 3.1 in GlassFish 3.1. Dependencies are managed by Maven 3. X
itself is Serializable
, to satisfy the passivating scopes.
Did you come across this before? What could I have done wrong?
Update: Added dependency management remark above.
Update: Corrected the position of @Actual
in Target
.
Update: Updated the description with more details after a day of experiments.
This appears to be a problem in Glassfish 3.1, in one of its included libraries, or possibly in JDK 6.
I have just updated my system to Glassfish 3.1.1 and JDK 7, and problem does not occur any longer.