Use this task to troubleshoot errors related to Contexts and Dependency Injection (CDI) for the Java™ Platform, Enterprise Edition (Java EE) applications.
When you use a CDI implementation, you might experience errors during application deployment or when CDI interacts with other Java EE components. You might also experience problems with producers, interceptors and decorators or diagnostic trace. Use this task to fix these errors that might occur.
An ambiguous dependency, or javax.enterprise.inject.AmbiguousResolutionException exception, occurs when the container resolves an injection points type and qualifiers to more than one managed bean, producer method, or producer field.
javax.enterprise.inject.AmbiguousResolutionException:
There is more than one api type with : com.ibm.websphere.samples.AppObject
with qualifiers : Qualifiers: [@com.ibm.websphere.samples.MyQualifier()]
for injection into Field Injection Point, field name : loginCheck,
Bean Owner : [Name:loginBean,WebBeans Type:MANAGED,API Types:[java.lang.
Object,com.ibm.websphere.samples.LoginBean],
Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.
Default,javax.inject.Named]]
found beans: Name:newObject,WebBeans Type:PRODUCERMETHOD, API Types:[com.ibm.websphere.
samples.AppObject,java.lang.Object], Qualifiers:[javax.enterprise.inject.
Any,com.ibm.websphere.samples.MyQualifier,javax.inject.Named]
Name:newObject2,WebBeans Type:PRODUCERMETHOD, API Types:[com.ibm.websphere.
samples.AppObject,java.lang.Object], Qualifiers:[javax.enterprise.inject.
Any,com.ibm.websphere.samples.MyQualifier,javax.inject.Named]
To
resolve the error complete one of the following actions:
javax.enterprise.inject.UnsatisfiedResolutionException: Api type
[com.ibm.websphere.samples.myType] is not found with the qualifiers
Qualifiers: [@javax.enterprise.inject.Default()]
for injection into Field Injection Point, field name : loginCheck,
Bean Owner : [Name:loginBean,WebBeans Type:MANAGED,
API Types:[java.lang.Object,com.ibm.websphere.samples.LoginBean],
Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.
inject.Default,javax.inject.Named]]
If the dependency is an Enterprise JavaBean (EJB) in a separate EJB module, verify the EJB module is listed in the classpath of the META-INF/MANIFEST.MF directory that is inside of the web project with the failing @Inject annotation. In Eclipse, establish this relationship under Deployment Assembly properties of the web project.
Caused by: org.apache.webbeans.exception.WebBeansConfigurationException:
Passivation scoped defined bean must be passivation
capable, but bean : Name:myCDIBean,WebBeans Type:MANAGED,API
Types:[com.ibm.websphere.samples.myCDIBean java.io.Serializable,java.lang.
Object,com.ibm.websphere.samples.myLocalIface],
Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.
Default,javax.inject.Named] is not passivation capable
The @Inject annotation provides an additional type of Java EE dependency injection. Its relation to injection that is defined in Java EE 5 is as follows:
org.apache.webbeans.exception.definition.DuplicateDefinitionException:
PassivationCapable bean id is not unique:
PRODUCERFIELD#class#com.ibm.websphere.samples.AppObject#
@javax.enterprise.inject.Any(),@com.ibm.websphere.samples.AppScopeBinding2
(),@javax.inject.Named(value=),
bean:Name:a2b,WebBeans Type:PRODUCERFIELD,API Types:[java.lang.Object,
com.ibm.websphere.samples.AppObject],
Qualifiers:[javax.enterprise.inject.Any,com.ibm.websphere.samples
.AppScopeBinding2,javax.inject.Named]
Each injection point for a given managed bean receives a new client proxy that calls the default constructor of the underlying bean class, in addition to the actual bean instance that might be created when using the proxy. Additionally, because dependency injections occur after the constructor completes, constructors cannot use injected dependencies. See the @PostConstruct annotation life cycle callback for a place to put post-injection logic that runs in the underlying instance only.
The CDI implementation uses OpenWebBeans and Javassist to create CDI proxy instances. Javassist does not proxy private methods so if a private method on a proxy instance is invoked, the method on the actual bean instance is never called. Since the method is being invoked on the proxy instance, it will only be able to access member variables for the proxy instance, not the actual bean instance. This is a Javassist limitation.
In general, only the CDI container can call private methods on a bean. Therefore, this is only a problem for private methods which have been annotated with certain CDI annotations such as @PostConstruct, @PreDestroy, or @Produces.
For example, if a proxied bean has a private @PostConstruct method which attempts to set the value of a class member variable, the variable it would be setting would be the one on the proxy instance. It would have no affect on the member variable on the actual bean instance.