我正在一个利用焊接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嵌入式容器和glassFilsh。我仔细检查了我的pom.xml
,我刚刚嵌入了玻璃鱼。我找不到焊接嵌入式容器的任何标志。有什么想法吗?!
答案 0 :(得分:0)
从maven本地存储库中删除其中一个容器。 maven本地存储库的默认位置是$HOME/.m2/repository/
。
如果您想使用Weld Embedded Server运行测试,请尝试删除org/jboss/arquillian/container/glassfish.embedded_3_1
,否则请删除org/jboss/arquillian/container/weld.ee.embedded_1_1
。
原因是,两个Jars都实现了相同的接口,而arquillian无法决定使用哪个接口。
答案 1 :(得分:0)
我是 Stack Overflow 的新手。因此,如果这不是我的提示的正确位置,请帮我将其移到那里。
我在使用 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>
我正在使用 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 解决了错误并且测试可以运行。