gpt4 book ai didi

java - Arquillian 中的多个容器错误

转载 作者:行者123 更新时间:2023-11-29 09:04:49 25 4
gpt4 key购买 nike

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

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

 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 embedded container又有glassFilsh。我仔细检查了我的 pom.xml ,我刚刚嵌入了 glassfish。我找不到任何焊接嵌入式容器的迹象。有什么想法吗?!

最佳答案

我在使用 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”。开始测试后我得到了异常:

Caused by: java.lang.IllegalStateException: Could not add a default container to registry because multiple instances of org.jboss.arquillian.container.spi.client.container.DeployableContainer found on classpath (candidates are: 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 解决了错误并且测试可以运行。

关于java - Arquillian 中的多个容器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15610267/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com