部署时出现 AmbiguousResolutionException WAR

AmbiguousResolutionException when deploying WAR

我在部署到 WildFly 8.2.1 时遇到一个奇怪的错误,这与 Resteasy 和 maven 设置有关。我已经浪费了无数小时谷歌搜索无济于事。
-无法实例化 MessageBodyReader
-AmbiguousResolutionException:WELD-001318:无法解决

之间的不明确依赖关系

项目组织:

-root  
-project  
--project-ear
--project-main
--project-rest
--project-jms

root pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>si.fri.liis.jmsprojekt</groupId>
    <artifactId>root</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.wildfly.bom</groupId>
                <artifactId>jboss-javaee-7.0-with-all</artifactId>
                <version>8.2.1.Final</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
            <dependency>
                <groupId>org.wildfly</groupId>
                <artifactId>wildfly-ejb-client-bom</artifactId>
                <version>8.2.0.Final</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
            <dependency>
                <groupId>javax</groupId>
                <artifactId>javaee-api</artifactId>
                <version>7.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax</groupId>
                <artifactId>javaee-web-api</artifactId>
                <version>7.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>resteasy-jaxrs</artifactId>
                <version>3.0.10.Final</version>
                <scope>provided</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.3</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-ear-plugin</artifactId>
                    <version>2.10</version>
                    <configuration>
                        <version>7</version>
                        <defaultLibBundleDir>lib</defaultLibBundleDir>
                        <generateApplicationXml>true</generateApplicationXml>
                        <fileNameMapping>no-version</fileNameMapping>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-ejb-plugin</artifactId>
                    <version>2.5</version>
                    <configuration>
                        <ejbVersion>3.2</ejbVersion>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                            </manifest>
                        </archive>
                        <generateClient>true</generateClient>
                        <clientIncludes>
                            <clientInclude>si/fri/liis/jmsprojekt/**/*SbRemote.class</clientInclude>
                            <clientInclude>si/fri/liis/jmsprojekt/**/*SbLocal.class</clientInclude>
                            <clientInclude>si/fri/liis/jmsprojekt/**/*Data.class</clientInclude>
                            <clientInclude>si/fri/liis/jmsprojekt/**/*Exception.class</clientInclude>
                        </clientIncludes>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.6</version>
                    <configuration>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                        <warName>jmsprojekt</warName>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>jaxb2-maven-plugin</artifactId>
                    <version>1.6</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

项目pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>si.fri.liis.jmsprojekt</groupId>
    <artifactId>root</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>../root/pom.xml</relativePath>
  </parent>

  <artifactId>jmsprojekt</artifactId>
  <packaging>pom</packaging>

    <modules>
        <module>jmsprojekt-ear</module>
        <module>jmsprojekt-main</module>
        <module>jmsprojekt-jms</module>
        <module>jmsprojekt-rest</module>
    </modules>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>si.fri.liis.jmsprojekt</groupId>
            <artifactId>jmsprojekt-main</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <type>ejb</type>
        </dependency>
        <dependency>
            <groupId>si.fri.liis.jmsprojekt</groupId>
            <artifactId>jmsprojekt-main</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <type>ejb-client</type>
        </dependency>
        <dependency>
            <groupId>si.fri.liis.jmsprojekt</groupId>
            <artifactId>jmsprojekt-jms</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <type>ejb</type>
        </dependency>
        <dependency>
            <groupId>si.fri.liis.jmsprojekt</groupId>
            <artifactId>jmsprojekt-rest</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <type>war</type>
        </dependency>
    </dependencies>
</dependencyManagement>
</project>

耳朵pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>si.fri.liis.jmsprojekt</groupId>
    <artifactId>jmsprojekt</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>

  <artifactId>jmsprojekt-ear</artifactId>
  <packaging>ear</packaging>

  <dependencies>
    <dependency>
        <groupId>si.fri.liis.jmsprojekt</groupId>
        <artifactId>jmsprojekt-main</artifactId>
        <type>ejb</type>
    </dependency>
    <dependency>
        <groupId>si.fri.liis.jmsprojekt</groupId>
        <artifactId>jmsprojekt-rest</artifactId>
        <type>war</type>
    </dependency>
    <dependency>
        <groupId>si.fri.liis.jmsprojekt</groupId>
        <artifactId>jmsprojekt-jms</artifactId>
        <type>ejb</type>
    </dependency>
  </dependencies>
</project>

休息pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>si.fri.liis.jmsprojekt</groupId>
    <artifactId>jmsprojekt</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>

  <artifactId>jmsprojekt-rest</artifactId>
  <packaging>war</packaging>

  <dependencies>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxrs</artifactId>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
        </dependency>
        <dependency>
            <groupId>si.fri.liis.jmsprojekt</groupId>
            <artifactId>jmsprojekt-main</artifactId>
            <type>ejb</type>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

WildFly 部署日志,太长无法粘贴: http://pastebin.com/NK4eaba1

从您的链接日志来看,您似乎包含了 resteasy 两次,它可能来自您的 "rest pom.xml"。看起来对 resteasy 的依赖可能默认为 compile 范围。与对 java-ee 的依赖相同。这些都应该是 provided 范围。

Caused by: org.jboss.weld.exceptions.AmbiguousResolutionException: WELD-001318: Cannot resolve an ambiguous dependency between: - Managed Bean [class org.jboss.resteasy.plugins.providers.jaxb.JAXBXmlSeeAlsoProvider] with qualifiers [@Any @Default], - Managed Bean [class org.jboss.resteasy.plugins.providers.jaxb.JAXBXmlSeeAlsoProvider] with qualifiers [@Any @Default]