2

我在一个使用焊接 CDI 和 JPA 的项目中安装 Arquillian,我正在尝试使用嵌入式 GlassFish 容器(我读到 Weld 嵌入式容器不支持 JPA)。

我在其中添加了 GlassFishContainer,pom.xml但是在运行测试用例时收到一条错误消息。这里 id 错误消息:

 Multiple service implementations found for interface 
org.jboss.arquillian.container.spi.client.container.DeployableContainer. 
org.jboss.arquillian.container.glassfish.embedded_3_1.GlassFishContainer,    
org.jboss.arquillian.container.weld.ee.embedded_1_1.WeldEEMockContainer

看来我有 Weld 嵌入式容器和 glassFilsh。我仔细检查了我的pom.xml,我刚刚嵌入了 glassfish。我找不到任何 Weld 嵌入式容器的迹象。任何想法?!

4

2 回答 2

1

我在使用 Maven 在 IntelliJ 中使用嵌入式 Tomcat-8 设置 Arquillian 时也遇到了这个错误。

这是我的工作(对于一个示例项目)POM:

<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>arquillilan.tomcat.test</groupId>
<artifactId>arquillianTest</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>arquillianTest</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <version.org.eclipse.jdt.core.compiler>3.7</version.org.eclipse.jdt.core.compiler>
    <version.weld_servlet>1.1.9.Final</version.weld_servlet>
    <version.arquillian>1.1.5.Final</version.arquillian>
    <version.tomcat>8.5.57</version.tomcat>
</properties>

<dependencies>
    <!-- org.jboss.arquillian -->
    <dependency>
        <groupId>org.jboss.arquillian.container</groupId>
        <artifactId>arquillian-container-spi</artifactId>
        <version>${version.arquillian}</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.jboss.arquillian.container/arquillian-container-test-spi -->
    <dependency>
        <groupId>org.jboss.arquillian.container</groupId>
        <artifactId>arquillian-container-test-spi</artifactId>
        <version>${version.arquillian}</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.arquillian.protocol</groupId>
        <artifactId>arquillian-protocol-servlet</artifactId>
        <version>${version.arquillian}</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.arquillian.testenricher</groupId>
        <artifactId>arquillian-testenricher-cdi</artifactId>
        <version>${version.arquillian}</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.arquillian.testenricher</groupId>
        <artifactId>arquillian-testenricher-resource</artifactId>
        <version>${version.arquillian}</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.arquillian.testenricher</groupId>
        <artifactId>arquillian-testenricher-initialcontext</artifactId>
        <version>${version.arquillian}</version>

    </dependency>

    <!-- org.apache.tomcat -->
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-core</artifactId>
        <version>${version.tomcat}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <version>${version.tomcat}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-logging-juli</artifactId>
        <version>8.5.2</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.eclipse.jdt.core.compiler</groupId>
        <artifactId>ecj</artifactId>
        <version>${version.org.eclipse.jdt.core.compiler}</version>
        <scope>provided</scope>
    </dependency>

    <!-- testing -->
    <dependency>
        <groupId>org.jboss.arquillian.junit</groupId>
        <artifactId>arquillian-junit-container</artifactId>
        <version>${version.arquillian}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.shrinkwrap.resolver</groupId>
        <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
        <version>1.0.0-beta-6</version>
        <!--  2.0.0-beta-4 is not working  ** we are using old version -->
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.shrinkwrap.descriptors</groupId>
        <artifactId>shrinkwrap-descriptors-impl-javaee</artifactId>
        <version>2.0.0-alpha-5</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.shrinkwrap.resolver</groupId>
        <artifactId>shrinkwrap-resolver-api-maven</artifactId>
        <version>1.0.0-beta-6</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>

    <!-- org.jboss.weld.resources.ManagerObjectFactory -->
    <dependency>
        <groupId>org.jboss.weld.servlet</groupId>
        <artifactId>weld-servlet</artifactId>
        <version>${version.weld_servlet}</version>
        <scope>test</scope>
    </dependency>


    <!-- Hibernate dependencies -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.1.6.Final</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.3.0.Final</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.2.2.Final</version>
    </dependency>

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.3.171</version>
    </dependency>

    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-dbcp</artifactId>
        <version>7.0.40</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/org.jboss.arquillian.container/arquillian-tomcat-embedded-8 -->
    <dependency>
        <groupId>org.jboss.arquillian.container</groupId>
        <artifactId>arquillian-tomcat-embedded-8</artifactId>
        <version>1.0.1.Final</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.arquillian.container</groupId>
        <artifactId>arquillian-tomcat-common</artifactId>
        <scope>test</scope>
        <version>1.0.1.Final</version>
    </dependency>

</dependencies>

</project>

我正在使用 Intellij 并配置了“Tomcat Embedded 8.x: AruillianTest”。开始测试后,我得到了异常:

原因:java.lang.IllegalStateException:无法将默认容器添加到注册表,因为在类路径上找到了 org.jboss.arquillian.container.spi.client.container.DeployableContainer 的多个实例(候选者是:org.jboss.arquillian.container .tomcat.embedded.TomcatEmbeddedConfiguration, org.jboss.arquillian.container.tomcat.embedded_8.TomcatConfiguration)

该问题是由 Intellij 进行的自动配置引起的。intellij_arquillian_configuration显示了解决错误所必须采取的路径。

1 - 点击“编辑配置” -> 它将打开 2

2 - 选择您要使用的嵌入式 Tomcat(在我的情况下为 Tomcat 8),然后单击 3 将打开 4

4 - 依赖项 (5) 是可点击的。双击打开 6.

6 - 选择与您的 pom.xml 完全相同的版本。我在我的 pom 中使用 1.0.1.Final 但我的测试容器配置了 1.0.0.CR7 (为此屏幕截图制作;通常是“RELEASE”)。将此更改为 1.0.1.FINAL 解决了错误并且可以运行测试。

于 2021-04-26T08:41:05.043 回答
0

从 Maven 本地存储库中删除一个容器。Maven 本地存储库的默认位置是$HOME/.m2/repository/.

org/jboss/arquillian/container/glassfish.embedded_3_1如果您想使用 Weld Embedded Server 运行测试,请尝试删除else delete org/jboss/arquillian/container/weld.ee.embedded_1_1

原因是,两个罐子都实现了相同的接口,而 arquillian 无法决定使用哪一个。

于 2014-05-17T08:00:54.307 回答