[
https://issues.jboss.org/browse/AS7-1662?page=com.atlassian.jira.plugin.s...
]
Marcus Portmann commented on AS7-1662:
--------------------------------------
The issue I am experiencing is that it is not possible to include the utility library
TestCommon in my TestWeb WAR project without specifying an alternative in the beans.xml
for the ITestService bean interface. Any web application making use of the shared utility
library will not be able to select between the alternative implementations of the
ITestService bean interface provided by the TestCommon utility library.
In the WebSphere CDI implementation it is possible to not specify any alternative in
META-INF/beans.xml file that forms part of the TestCommon JAR. As long as an alternative
is specified in the WEB-INF/beans.xml file that forms part of the TestWeb WAR all
dependencies are resolved correctly.
I am not that familiar with the CDI spec but it seems strange that there is no requirement
to allow dependencies to be resolved using the alternatives specified across all the
beans.xml files. It is a pity that a consumer of a third party library containing managed
beans in JBoss won't be able to select the specific alternative for the managed bean
that suits their needs.
Incorrect resolution of managed bean alternatives for
------------------------------------------------------
Key: AS7-1662
URL:
https://issues.jboss.org/browse/AS7-1662
Project: Application Server 7
Issue Type: Bug
Components: CDI / Weld
Affects Versions: 7.0.1.Final
Environment: Mac OS X Version 10.7
Reporter: Marcus Portmann
Assignee: Stuart Douglas
Fix For: 7.0.1.Final
Given a JEE EAR project Test that includes a WAR project TestWeb which references a Java
project TestCommon as a deployment assembly.
In the TestCommon project I have a managed bean named TestService annotated with the
@ApplicationScope and @Alternative annotations that implements the interface ITestService.
In the TestCommon project I have another managed bean named AnotherTestService that
injects the TestService implementation using an @Inject annotation on a private variable
of type ITestService.
In the TestWeb application I have a servlet which injects the TestService implementation
using an @Inject annotation on a private variable of type ITestService.
I have added a beans.xml file to my WEB-INF folder for the TestWeb WAR and declared the
TestService class as an alternative.
I attempted to add a beans.xml file to the META-INF folder under the TestCommon project
without any alternative classes specified.
When I attempt to deploy my application on JBoss 7.0.1 I receive the error
"WELD-001408 Unsatisfied dependencies for type [ITestService] with qualifiers
[@Default] at injection point [[field] @Inject private
absa.test.model.AnotherTestService.testService]".
It appears that Weld is not using the alternative specified in the WEB-INF/beans.xml file
that forms part of the TestWeb WAR. Instead Weld is trying to resolve the alternative only
using the META-INF/beans.xml file that forms part of the TestCommon JAR.
If I add the TestService class as an alternative to the META-INF/beans.xml file that
forms part of the TestCommon JAR then the application deploys successfully.
If I add another alternative implementation for the ITestService interface to the
TestCommon JAR project and reference this alternative in the WEB-INF/beans.xml file that
forms part of the TestWeb WAR then the servlet is injected with this new implementation.
The AnotherTestService though is still injected with the alternative specified in the
META-INF/beans.xml file for the TestCommon JAR.
It appears as if Weld is not overriding the alternative specified in the
META-INF/beans.xml file for the TestCommon JAR with the alternative specified in the
WEB-INF/beans.xml file that forms part of the TestWeb WAR.
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira