I have some troubles with injecting POJOs via @Inject using Wildfly. The documentation clearly states:
@Dependent - The default scope if none is specified; it means that an object exists to serve exactly one client (bean) and has the same lifecycle as that client (bean).
However, when I have two classes:
@Singleton
@Startup
public class A{
@Inject
private B b;
}
public class B{
public B(){}
}
I keep getting:
Unsatisfied dependencies for type B with qualifiers @Default at injection point [BackedAnnotatedField] @Inject [...]
When I add @Dependent everything works like a charm. Am I missing something? Is this behavior wildfly-specific? Hope you can help, thanks.
When using CDI in Java EE 7 (CDI 1.1), the default bean discovery mode is
annotated
. Which means that any bean with an explicitly specified scope is available for injection.So to make your bean B available for injection, you can either:
@Dependent
)beans.xml
file with thebean-discovery-mode
attribute set toall
. This will make all beans of your archive available for injection (same behavior than Java EE 6 (CDI 1.0)).The
beans.xml
file must be in theMETA-INF
folder and looks like:However, i would not recommend using
bean-discovery-mode="all"
.