问题
I have one class declared this way:
@ApplicationScoped
public class MessageHandlerImpl implements MessageHandler {
...
}
and I inject it on another class like this:
@ApplicationScoped
public class MessageReceiverImpl implements MessageReceiver {
@Inject
MessageHandler messageHandler;
...
}
When I try to start my application I receive the following exception:
org.jboss.weld.exceptions.DeploymentException: WELD-001409: Ambiguous
dependencies for type MessageHandler with qualifiers @Default at
injection point [BackedAnnotatedField] @Inject
com.company.core.WSClient.messageHandler at com.company.core.WSClient.messageHandler(WSClient.java:0)
Possible dependencies:
- Managed Bean [class com.company.core.MessageReceiverImpl] with qualifiers [@Any @Default],
- Managed Bean [class com.company.core.MessageReceiverImpl] with qualifiers [@Any @Default]
You might notice that the same class appears two times on the possible beans list.
This was all working fine until I isolated those classes on a separated project called "core" and started using them on a different maven project that has the core as a dependency.
My guess would be that the problem its caused by this project separation. Do I need to do something different when the dependencies come from a different project?
I'm running the application with:
mvn wildfly-swarm:run
Wildfly-swarm generates an uber-jar with everything to make the final jar independent. Looking inside the final jar there is a "maven repository" with all the dependencies and there is only one jar from "com.company" which is the one I was expecting (the core).
The pom files are like this:
Core:
<groupId>com.company</groupId>
<artifactId>core</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
Depedent project:
<dependency>
<groupId>com.company</groupId>
<artifactId>core</artifactId>
<version>0.0.1</version>
</dependency>
mvn dependency:tree
[INFO] com.company:dependent-project:jar:0.0.1
[INFO] +- com.company:another-project:jar:1.4.2:compile
[INFO] | \- org.springframework:spring-beans:jar:4.1.6.RELEASE:compile
[INFO] | \- org.springframework:spring-core:jar:4.1.6.RELEASE:compile
[INFO] +- com.company:core:jar:0.0.1:compile
[INFO] +- info.cukes:cucumber-junit:jar:1.2.5:compile
[INFO] | \- info.cukes:cucumber-core:jar:1.2.5:compile
[INFO] | +- info.cukes:cucumber-html:jar:0.2.3:compile
[INFO] | +- info.cukes:cucumber-jvm-deps:jar:1.0.5:compile
[INFO] | \- info.cukes:gherkin:jar:2.12.2:compile
[INFO] +- info.cukes:cucumber-java:jar:1.2.5:test
[INFO] +- com.google.protobuf:protobuf-java:jar:3.4.0:compile
[INFO] +- org.zeromq:jeromq:jar:0.4.2:compile
[INFO] | \- org.zeromq:jnacl:jar:0.1.0:compile
[INFO] +- org.wildfly.swarm:keycloak:jar:2017.6.0:compile
[INFO] | +- org.wildfly.swarm:container:jar:2017.6.0:compile
[INFO] | | +- org.wildfly.swarm:spi:jar:2017.6.0:compile
[INFO] | | | \- org.jboss:jandex:jar:2.0.2.Final:compile
[INFO] | | \- org.wildfly.swarm:config-api:jar:1.1.0.Final:compile
[INFO] | +- org.wildfly.swarm:undertow:jar:2017.6.0:compile
[INFO] | | +- org.wildfly.swarm:io:jar:2017.6.0:compile
[INFO] | | +- org.wildfly.swarm:request-controller:jar:2017.6.0:compile
[INFO] | | +- org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-api-jboss:jar:2.0.0:compile
[INFO] | | +- org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-impl-jboss:jar:2.0.0:compile
[INFO] | | +- org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-api-javaee:jar:2.0.0:compile
[INFO] | | | \- org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-api-base:jar:2.0.0:compile
[INFO] | | +- org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-impl-javaee:jar:2.0.0:compile
[INFO] | | | \- org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-impl-base:jar:2.0.0:compile
[INFO] | | +- org.jboss.spec.javax.servlet:jboss-servlet-api_3.1_spec:jar:1.0.0.Final:compile
[INFO] | | +- org.jboss.spec.javax.websocket:jboss-websocket-api_1.1_spec:jar:1.1.1.Final:compile
[INFO] | | \- io.undertow:undertow-servlet:jar:1.4.11.Final:compile
[INFO] | | \- io.undertow:undertow-core:jar:1.4.11.Final:compile
[INFO] | | +- org.jboss.xnio:xnio-api:jar:3.4.3.Final:compile
[INFO] | | \- org.jboss.xnio:xnio-nio:jar:3.4.3.Final:runtime
[INFO] | +- org.wildfly.swarm:security:jar:2017.6.0:compile
[INFO] | +- org.wildfly.swarm:keycloak-client-config-api:jar:1.1.0.Final:compile
[INFO] | | \- org.wildfly.swarm:config-api-runtime:jar:1.1.0.Final:compile
[INFO] | \- org.keycloak:keycloak-core:jar:2.5.4.Final:compile
[INFO] | +- org.keycloak:keycloak-common:jar:2.5.4.Final:compile
[INFO] | +- org.bouncycastle:bcprov-jdk15on:jar:1.52:compile
[INFO] | \- org.bouncycastle:bcpkix-jdk15on:jar:1.52:compile
[INFO] +- org.wildfly.swarm:jaxrs-validator:jar:2017.6.0:compile
[INFO] | +- org.wildfly.swarm:hibernate-validator:jar:2017.6.0:compile
[INFO] | | +- org.jboss.spec.javax.el:jboss-el-api_3.0_spec:jar:1.0.7.Final:compile
[INFO] | | \- org.glassfish:javax.el-impl:jar:3.0.1-b08-jbossorg-1:compile
[INFO] | \- org.wildfly.swarm:meta-spi:jar:2017.6.0:compile
[INFO] +- org.mongodb:mongo-java-driver:jar:3.4.2:compile
[INFO] +- org.mapstruct:mapstruct-jdk8:jar:1.2.0.Beta2:compile
[INFO] +- org.mapstruct:mapstruct-processor:jar:1.2.0.Beta2:provided
[INFO] +- org.apache.commons:commons-text:jar:1.1:compile
[INFO] +- org.wildfly.swarm:jpa:jar:2017.6.0:compile
[INFO] | +- org.wildfly.swarm:datasources:jar:2017.6.0:compile
[INFO] | | \- org.jboss.ironjacamar:ironjacamar-jdbc:jar:1.3.4.Final:compile
[INFO] | +- org.wildfly.swarm:ee:jar:2017.6.0:compile
[INFO] | | +- org.wildfly.swarm:naming:jar:2017.6.0:compile
[INFO] | | +- org.jboss.spec.javax.enterprise.concurrent:jboss-concurrency-api_1.0_spec:jar:1.0.0.Final:compile
[INFO] | | \- org.jboss.spec.javax.interceptor:jboss-interceptors-api_1.2_spec:jar:1.0.0.Final:compile
[INFO] | +- org.wildfly.swarm:bootstrap:jar:2017.6.0:compile
[INFO] | | +- org.jboss.modules:jboss-modules:jar:1.5.2.Final:compile
[INFO] | | \- org.yaml:snakeyaml:jar:1.15:compile
[INFO] | \- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] +- javax:javaee-api:jar:7.0:provided
[INFO] | \- com.sun.mail:javax.mail:jar:1.5.5:provided
[INFO] +- org.wildfly.swarm:ejb:jar:2017.6.0:compile
[INFO] | +- org.wildfly.swarm:jca:jar:2017.6.0:compile
[INFO] | | \- org.wildfly.swarm:connector:jar:2017.6.0:compile
[INFO] | | \- org.jboss.spec.javax.resource:jboss-connector-api_1.7_spec:jar:1.0.0.Final:compile
[INFO] | +- org.jboss.spec.javax.ejb:jboss-ejb-api_3.2_spec:jar:1.0.0.Final:compile
[INFO] | \- org.jboss.ejb3:jboss-ejb3-ext-api:jar:2.2.0.Final:compile
[INFO] +- org.wildfly.swarm:cdi:jar:2017.6.0:compile
[INFO] | +- org.wildfly.swarm:cdi-config:jar:2017.6.0:compile
[INFO] | +- org.wildfly.swarm:bean-validation:jar:2017.6.0:compile
[INFO] | +- org.wildfly.swarm:transactions:jar:2017.6.0:compile
[INFO] | | +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.0.Final:compile
[INFO] | | \- org.jboss.narayana.jts:narayana-jts-idlj:jar:5.3.3.Final:compile
[INFO] | | \- org.jboss.openjdk-orb:openjdk-orb:jar:8.0.6.Final:compile
[INFO] | +- javax.enterprise:cdi-api:jar:1.2:compile
[INFO] | \- javax.inject:javax.inject:jar:1:compile
[INFO] +- org.wildfly.swarm:jaxrs:jar:2017.6.0:compile
[INFO] | +- org.ow2.asm:asm-all:jar:5.0.4:compile
[INFO] | +- org.jboss.spec.javax.ws.rs:jboss-jaxrs-api_2.0_spec:jar:1.0.0.Final:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-core:jar:2.7.4:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.7.4:compile
[INFO] | \- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.7.4:compile
[INFO] | +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.7.4:compile
[INFO] | \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.7.4:compile
[INFO] +- org.wildfly.swarm:jaxrs-cdi:jar:2017.6.0:compile
[INFO] +- org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-api-maven:jar:2.2.4:compile
[INFO] | \- org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-api:jar:2.2.4:compile
[INFO] +- org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-impl-maven:jar:2.2.4:compile
[INFO] | +- org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-spi-maven:jar:2.2.4:compile
[INFO] | | \- org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-spi:jar:2.2.4:compile
[INFO] | +- org.eclipse.aether:aether-api:jar:1.0.0.v20140518:compile
[INFO] | +- org.eclipse.aether:aether-impl:jar:1.0.0.v20140518:compile
[INFO] | +- org.eclipse.aether:aether-spi:jar:1.0.0.v20140518:compile
[INFO] | +- org.eclipse.aether:aether-util:jar:1.0.0.v20140518:compile
[INFO] | +- org.eclipse.aether:aether-connector-basic:jar:1.0.0.v20140518:compile
[INFO] | +- org.eclipse.aether:aether-transport-wagon:jar:1.0.0.v20140518:compile
[INFO] | +- org.apache.maven:maven-aether-provider:jar:3.2.5:provided
[INFO] | +- org.apache.maven:maven-model:jar:3.2.5:compile
[INFO] | +- org.apache.maven:maven-model-builder:jar:3.2.5:compile
[INFO] | | \- org.codehaus.plexus:plexus-component-annotations:jar:1.5.5:compile
[INFO] | +- org.apache.maven:maven-repository-metadata:jar:3.2.5:compile
[INFO] | +- org.apache.maven:maven-settings:jar:3.2.5:compile
[INFO] | +- org.apache.maven:maven-settings-builder:jar:3.2.5:compile
[INFO] | +- org.codehaus.plexus:plexus-interpolation:jar:1.21:compile
[INFO] | +- org.codehaus.plexus:plexus-utils:jar:3.0.21:compile
[INFO] | +- org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3:compile
[INFO] | | \- org.sonatype.plexus:plexus-cipher:jar:1.4:compile
[INFO] | +- org.apache.maven.wagon:wagon-provider-api:jar:2.6:compile
[INFO] | +- org.apache.maven.wagon:wagon-file:jar:2.6:compile
[INFO] | \- org.apache.maven.wagon:wagon-http-lightweight:jar:2.6:compile
[INFO] | \- org.apache.maven.wagon:wagon-http-shared:jar:2.6:compile
[INFO] | \- org.jsoup:jsoup:jar:1.8.3:compile
[INFO] +- org.wildfly.swarm:logging:jar:2017.6.0:compile
[INFO] | \- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- org.jboss.resteasy:resteasy-jaxrs:jar:3.0.19.Final:provided
[INFO] | +- org.jboss.spec.javax.annotation:jboss-annotations-api_1.2_spec:jar:1.0.0.Final:compile
[INFO] | \- javax.activation:activation:jar:1.1.1:provided
[INFO] +- org.jboss.resteasy:jaxrs-api:jar:3.0.6.Final:provided
[INFO] +- org.jboss.resteasy:resteasy-validator-provider-11:jar:3.0.19.Final:provided
[INFO] | \- com.fasterxml:classmate:jar:1.3.1:compile
[INFO] +- org.jboss.resteasy:resteasy-multipart-provider:jar:3.0.19.Final:provided
[INFO] | +- org.jboss.resteasy:resteasy-client:jar:3.0.19.Final:provided
[INFO] | +- org.jboss.resteasy:resteasy-jaxb-provider:jar:3.0.19.Final:provided
[INFO] | \- org.apache.james:apache-mime4j:jar:0.6:provided
[INFO] +- org.jboss.resteasy:resteasy-jackson2-provider:jar:3.0.19.Final:compile
[INFO] +- javax.annotation:javax.annotation-api:jar:1.2:provided
[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.4.1:compile
[INFO] +- joda-time:joda-time:jar:2.7:compile
[INFO] +- io.swagger:swagger-jaxrs:jar:1.5.16:compile
[INFO] | +- io.swagger:swagger-core:jar:1.5.16:compile
[INFO] | | +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.8.9:compile
[INFO] | | \- io.swagger:swagger-models:jar:1.5.16:compile
[INFO] | | \- io.swagger:swagger-annotations:jar:1.5.16:compile
[INFO] | +- javax.ws.rs:jsr311-api:jar:1.1.1:compile
[INFO] | \- org.reflections:reflections:jar:0.9.11:compile
[INFO] | \- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] +- com.google.guava:guava:jar:20.0:compile
[INFO] +- junit:junit:jar:4.11:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- commons-logging:commons-logging:jar:1.2:compile
[INFO] +- javax.validation:validation-api:jar:1.1.0.Final:provided
[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.7.4:compile
[INFO] +- org.hibernate:hibernate-validator:jar:5.2.4.Final:compile
[INFO] +- org.glassfish:javax.el:jar:3.0.1-b08:compile
[INFO] +- org.hibernate:hibernate-validator-cdi:jar:5.2.4.Final:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.5:compile
[INFO] | +- org.apache.httpcomponents:httpcore:jar:4.4.1:compile
[INFO] | \- commons-codec:commons-codec:jar:1.10:compile
[INFO] +- org.postgresql:postgresql:jar:42.1.4:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.22:compile
[INFO] +- org.slf4j:slf4j-nop:jar:1.7.22:test
[INFO] +- org.wildfly.swarm:arquillian:jar:2017.6.0:test
[INFO] | +- org.wildfly.swarm:arquillian-daemon:jar:2017.6.0:test
[INFO] | | +- org.wildfly.core:wildfly-server:jar:2.2.1.Final:test
[INFO] | | | +- org.wildfly.core:wildfly-controller:jar:2.2.1.Final:test
[INFO] | | | | +- org.wildfly.core:wildfly-controller-client:jar:2.2.1.Final:test
[INFO] | | | | +- org.wildfly.core:wildfly-core-security:jar:2.2.1.Final:test
[INFO] | | | | | \- org.wildfly.core:wildfly-core-security-api:jar:2.2.1.Final:test
[INFO] | | | | \- org.jboss:staxmapper:jar:1.2.0.Final:test
[INFO] | | | +- org.wildfly.core:wildfly-domain-http-interface:jar:2.2.1.Final:test
[INFO] | | | | \- org.wildfly.core:wildfly-domain-management:jar:2.2.1.Final:test
[INFO] | | | | \- org.picketbox:picketbox:jar:4.9.6.Final:test
[INFO] | | | +- org.wildfly.core:wildfly-deployment-repository:jar:2.2.1.Final:test
[INFO] | | | | \- org.wildfly.core:wildfly-protocol:jar:2.2.1.Final:test
[INFO] | | | +- org.wildfly.core:wildfly-platform-mbean:jar:2.2.1.Final:test
[INFO] | | | +- org.wildfly.core:wildfly-process-controller:jar:2.2.1.Final:test
[INFO] | | | +- org.wildfly.core:wildfly-remoting:jar:2.2.1.Final:test
[INFO] | | | | \- org.wildfly.core:wildfly-io:jar:2.2.1.Final:test
[INFO] | | | +- org.wildfly.core:wildfly-network:jar:2.2.1.Final:test
[INFO] | | | +- org.wildfly.core:wildfly-self-contained:jar:2.2.1.Final:test
[INFO] | | | +- org.wildfly.security:wildfly-elytron:jar:1.0.2.Final:test
[INFO] | | | +- org.wildfly.core:wildfly-version:jar:2.2.1.Final:test
[INFO] | | | +- org.jboss:jboss-dmr:jar:1.3.0.Final:test
[INFO] | | | +- org.jboss.invocation:jboss-invocation:jar:1.4.1.Final:test
[INFO] | | | +- org.jboss.marshalling:jboss-marshalling:jar:1.4.11.Final:test
[INFO] | | | +- org.jboss.remoting:jboss-remoting:jar:4.0.21.Final:test
[INFO] | | | +- org.jboss.sasl:jboss-sasl:jar:1.0.5.Final:test
[INFO] | | | +- org.jboss.stdio:jboss-stdio:jar:1.0.2.GA:test
[INFO] | | | +- org.jboss.threads:jboss-threads:jar:2.2.1.Final:test
[INFO] | | | +- org.jboss:jboss-vfs:jar:3.2.12.Final:test
[INFO] | | | \- org.wildfly.common:wildfly-common:jar:1.1.0.Final:compile
[INFO] | | \- org.jboss.msc:jboss-msc:jar:1.2.6.Final:test
[INFO] | \- org.wildfly.swarm:arquillian-adapter:jar:2017.6.0:test
[INFO] | +- org.wildfly.swarm:arquillian-resolver:jar:2017.6.0:test
[INFO] | +- org.wildfly.swarm:fraction-metadata:jar:2017.6.0:test
[INFO] | | \- com.eclipsesource.minimal-json:minimal-json:jar:0.9.4:test
[INFO] | +- org.wildfly.swarm:tools:jar:2017.6.0:test
[INFO] | | \- net.lingala.zip4j:zip4j:jar:1.3.2:test
[INFO] | +- org.wildfly.swarm:msc:jar:2017.6.0:test
[INFO] | +- org.jboss.arquillian.container:arquillian-container-spi:jar:1.1.10.Final:test
[INFO] | +- org.jboss.arquillian.testenricher:arquillian-testenricher-cdi:jar:1.1.10.Final:test
[INFO] | +- org.jboss.arquillian.testenricher:arquillian-testenricher-ejb:jar:1.1.10.Final:test
[INFO] | +- org.jboss.arquillian.testenricher:arquillian-testenricher-resource:jar:1.1.10.Final:test
[INFO] | +- org.jboss.arquillian.testenricher:arquillian-testenricher-initialcontext:jar:1.1.10.Final:test
[INFO] | \- org.jboss.arquillian.config:arquillian-config-impl-base:jar:1.1.12.Final:test
[INFO] +- org.jboss.arquillian.junit:arquillian-junit-container:jar:1.1.10.Final:test
[INFO] | +- org.jboss.arquillian.junit:arquillian-junit-core:jar:1.1.10.Final:test
[INFO] | +- org.jboss.arquillian.test:arquillian-test-api:jar:1.1.12.Final:test
[INFO] | | \- org.jboss.arquillian.core:arquillian-core-api:jar:1.1.10.Final:test
[INFO] | +- org.jboss.arquillian.test:arquillian-test-spi:jar:1.1.10.Final:test
[INFO] | | \- org.jboss.arquillian.core:arquillian-core-spi:jar:1.1.10.Final:test
[INFO] | +- org.jboss.arquillian.container:arquillian-container-test-api:jar:1.1.10.Final:test
[INFO] | | \- org.jboss.shrinkwrap:shrinkwrap-api:jar:1.2.6:compile
[INFO] | +- org.jboss.arquillian.container:arquillian-container-test-spi:jar:1.1.10.Final:test
[INFO] | +- org.jboss.arquillian.core:arquillian-core-impl-base:jar:1.1.10.Final:test
[INFO] | +- org.jboss.arquillian.test:arquillian-test-impl-base:jar:1.1.10.Final:test
[INFO] | +- org.jboss.arquillian.container:arquillian-container-impl-base:jar:1.1.12.Final:test
[INFO] | | +- org.jboss.arquillian.config:arquillian-config-api:jar:1.1.12.Final:test
[INFO] | | \- org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-spi:jar:2.0.0:compile
[INFO] | +- org.jboss.arquillian.container:arquillian-container-test-impl-base:jar:1.1.10.Final:test
[INFO] | \- org.jboss.shrinkwrap:shrinkwrap-impl-base:jar:1.2.6:compile
[INFO] | \- org.jboss.shrinkwrap:shrinkwrap-spi:jar:1.2.6:compile
[INFO] +- org.jacoco:org.jacoco.core:jar:0.7.9:test
[INFO] | \- org.ow2.asm:asm-debug-all:jar:5.2:test
[INFO] +- org.mockito:mockito-all:jar:2.0.2-beta:test
[INFO] +- org.powermock:powermock-module-junit4:jar:1.6.6:test
[INFO] | \- org.powermock:powermock-module-junit4-common:jar:1.6.6:test
[INFO] | +- org.powermock:powermock-core:jar:1.6.6:test
[INFO] | \- org.powermock:powermock-reflect:jar:1.6.6:test
[INFO] +- org.powermock:powermock-api-mockito:jar:1.6.6:test
[INFO] | +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] | | \- org.objenesis:objenesis:jar:2.1:test
[INFO] | \- org.powermock:powermock-api-mockito-common:jar:1.6.6:test
[INFO] | \- org.powermock:powermock-api-support:jar:1.6.6:test
[INFO] +- org.apache.commons:commons-lang3:jar:3.5:compile
[INFO] +- org.infinispan:infinispan-embedded:jar:9.0.0.Final:compile
[INFO] | \- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.1.Final:compile
[INFO] +- com.typesafe.akka:akka-actor_2.12:jar:2.5.3:compile
[INFO] | +- org.scala-lang:scala-library:jar:2.12.2:compile
[INFO] | +- com.typesafe:config:jar:1.3.1:compile
[INFO] | \- org.scala-lang.modules:scala-java8-compat_2.12:jar:0.8.0:compile
[INFO] \- com.google.code.gson:gson:jar:2.8.1:compile
来源:https://stackoverflow.com/questions/47632542/ambiguous-dependency-with-only-one-applicationscoped-class