Arquillian:尝试多次注册同一个Observer ServerSetupObserver [英] Arquillian: Attempted to register the same Observer, ServerSetupObserver multiple times

查看:193
本文介绍了Arquillian:尝试多次注册同一个Observer ServerSetupObserver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用wildfly配置arquillian,但是在运行测试过程中遇到以下错误:

  java。 lang.RuntimeException:无法在org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:165)中创建类org.jboss.arquillian.test.impl.EventTestRunnerAdaptor 
的新实例... ....
引起的:java.lang.reflect.InvocationTargetException:null
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
.......... 。
导致:java.lang.RuntimeException:无法在org.jboss.arquillian.core.spi.SecurityActions.newInstance创建类org.jboss.arquillian.core.impl.ManagerImpl
的新实例(SecurityActions.java:165)
at .................
导致:java.lang.reflect.InvocationTargetException:null
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.new Instance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at ...............
导致:java.lang.RuntimeException:无法在org.jboss.arquillian.core创建和处理管理器
。 impl.ManagerImpl。< init>(ManagerImpl.java:105)......
引起的:java.lang.IllegalArgumentException:尝试注册同一个Observer:org.jboss.as.arquillian.container .ServerSetupObserver多次,请检查classpath是否有冲突的jar版本
在org.jboss.arquillian.core.impl.ManagerImpl $ 2.observer(ManagerImpl.java:354)
在org.jboss.arquillian.core .impl.loadable.LoadableExtensionLoader $ 1.observer(LoadableExtensionLoader.java:101)
在org.jboss.as.arquillian.container.CommonContainerExtension.register(CommonContainerExtension.java:41)
在org.jbos s.asarar.rar .xml

 < properties> 
< project.build.sourceEncoding> UTF-8< /project.build.sourceEncoding>
<! - maven-compiler-plugin - >
< maven.compiler.target> 1.7< /maven.compiler.target>
< maven.compiler.source> 1.7< /maven.compiler.source>
<! - 构建细节 - >
< timestamp> $ {maven.build.timestamp}< / timestamp>
< maven.build.timestamp.format> yyyy-MM-dd HH:mm:ss< /maven.build.timestamp.format>
< build_version> $ {project.version}< / build_version>
< build_number> 00001< / build_number>
<! - 依赖版本变量 - >
< struts2.version> 2.3.24< /struts2.version>
< hibernate.version> 4.3.9.Final< / hibernate.version>
< resteasy.version> 3.0.11.Final< /resteasy.version>
< apache.common.version> 3.3.2< /apache.common.version>
< junit-version> 4.12< / junit-version>
< arquillian-version> 1.1.8.Final< / arquillian-version>
< arquillian-transaction-version> 1.0.1.Final< / arquillian-transaction-version>
< arquillian-wildfly-version> 8.2.0.Final< / arquillian-wildfly-version>
< / properties>
< repositories>
< repository>
< id> JBoss Repository< / id>
< url> https://repository.jboss.org/nexus/content/groups/public/< / url>
< / repository>
< / repositories>
< dependencyManagement>
<依赖关系>
<依赖关系>
< groupId> org.jboss.spec< / groupId>
< artifactId> jboss-javaee-7.0< / artifactId>
< version> 1.0.0.Final< / version>
< type> pom< / type>
< scope> import< / scope>
< / dependency>
<! - -JUNIT - >
<依赖关系>
< groupId> junit< / groupId>
< artifactId> junit< / artifactId>
< version> $ {junit-version}< / version>
< / dependency>
<! - Arquillian本身 - >
<依赖关系>
< groupId> org.jboss.arquillian< / groupId>
< artifactId> arquillian-bom< / artifactId>
< version> $ {arquillian-version}< / version>
< scope> import< / scope>
< type> pom< / type>
< / dependency>
<! - 这是扩展arquillian它是可选的 - >
<依赖关系>
< groupId> org.jboss.arquillian.extension< / groupId>
< artifactId> arquillian-transaction-bom< / artifactId>
< version> $ {arquillian-transaction-version}< / version>
< type> pom< / type>
< scope> import< / scope>
< / dependency>
<! - 这是wildfly的容器适配器 - >
<依赖关系>
< groupId> org.wildfly< / groupId>
< artifactId> wildfly-arquillian-container-embedded< / artifactId>
< version> $ {arquillian-wildfly-version}< / version>
< / dependency>
< / dependencies>
< / dependencyManagement>
<依赖关系>
<依赖关系>
< groupId> log4j< / groupId>
< artifactId> log4j< / artifactId>
< version> 1.2.17< / version>
< / dependency>

<! - 测试依赖关系 - >
<依赖关系>
< groupId> junit< / groupId>
< artifactId> junit< / artifactId>
< scope> test< / scope>
< / dependency>
<依赖关系>
< groupId> org.jboss.arquillian.junit< / groupId>
< artifactId> arquillian-junit-container< / artifactId>
< version> 1.1.8.Final< / version>
< scope> test< / scope>
< / dependency>
<依赖关系>
< groupId> org.wildfly< / groupId>
< artifactId> wildfly-arquillian-container-embedded< / artifactId>
< scope> test< / scope>
< / dependency>
<依赖关系>
< groupId> org.jboss.arquillian.extension< / groupId>
< artifactId> arquillian-transaction-jta< / artifactId>
< scope> test< / scope>
< / dependency>
<依赖关系>
< groupId> org.jboss.arquillian.protocol< / groupId>
< artifactId> arquillian-protocol-servlet< / artifactId>
< scope> test< / scope>
< / dependency>
<依赖关系>
< groupId> org.jboss.weld< / groupId>
< artifactId> weld-core< / artifactId>
< version> 1.1.5.Final< / version>
< scope> test< / scope>
< / dependency>
<依赖关系>
< groupId> org.slf4j< / groupId>
< artifactId> slf4j-simple< / artifactId>
< version> 1.6.4< / version>
< scope> test< / scope>
< / dependency>

<! - struts 2依赖关系 - >
<依赖关系>
< groupId> org.apache.struts< / groupId>
< artifactId> struts2-core< / artifactId>
< version> $ {struts2.version}< / version>
< / dependency>
<依赖关系>
< groupId> org.apache.struts< / groupId>
< artifactId> struts2-convention-plugin< / artifactId>
< version> $ {struts2.version}< / version>
< / dependency>
<依赖关系>
< groupId> org.apache.struts< / groupId>
< artifactId> struts2-json-plugin< / artifactId>
< version> $ {struts2.version}< / version>
< / dependency>

<! - 导入CDI API - >
<依赖关系>
< groupId> org.apache.struts< / groupId>
< artifactId> struts2-cdi-plugin< / artifactId>
< version> $ {struts2.version}< / version>
< / dependency>
<依赖关系>
< groupId> javax.enterprise< / groupId>
< artifactId> cdi-api< / artifactId>
< version> 1.2< / version><! - $ NO-MVN-MAN-VER $ - >
< / dependency>

<! - 导入公共注释API(JSR-250) - >
<依赖关系>
< groupId> org.jboss.spec.javax.annotation< / groupId>
< artifactId> jboss-annotations-api_1.2_spec< / artifactId>
< / dependency>

<! - 导入Servlet API - >
<依赖关系>
< groupId> org.jboss.spec.javax.servlet< / groupId>
< artifactId> jboss-servlet-api_3.1_spec< / artifactId>
< / dependency>

<依赖关系>
< groupId> javax< / groupId>
< artifactId> javaee-api< / artifactId>
< version> 7.0< / version>
< / dependency>

<! - Jboss焊接 - >
<依赖关系>
< groupId> org.jboss.weld< / groupId>
< artifactId> weld-core< / artifactId>
< version> 2.2.2.Final< / version>
< scope>已提供< / scope>
< / dependency>

< / dependencies>
< build>
< finalName> fms< / finalName>
< resources>
< resource>
< directory> src / main / resources< / directory>
< filtering> true< / filtering>
< / resource>
< / resources>
< testResources>
< testResource>
< directory> src / test / resources< / directory>
< filtering> true< / filtering>
< / testResource>
< / testResources>
< plugins>
< plugin>
< groupId> org.wildfly.plugins< / groupId>
< artifactId> wildfly-maven-plugin< / artifactId>
< version> 1.0.0.Final< / version>
< / plugin>
< plugin>
< groupId> org.apache.maven.plugin< / groupId>
< artifactId> maven-resources-plugin< / artifactId>
< version> 2.6< / version>
< / plugin>
< plugin>
< artifactId> maven-surefire-plugin< / artifactId>
< version> 2.18.1< / version>
< / plugin>
< / plugins>
< / build>
<个人资料>
<个人资料>
<! - 一个可选的Arquillian测试配置文件,用于在
Wildfly实例中执行测试 - >
<! - 此配置文件将启动一个新的Wildfly实例,并执行
测试,在完成时将其关闭 - >
<! - 运行:mvn clean test -Parq-wildfly-managed - >
< id> arq-wildfly-managed< / id>
<依赖关系>
<依赖关系>
< groupId> org.wildfly.arquillian< / groupId>
< artifactId> wildfly-arquillian-container-managed< / artifactId>
< version> 1.0.0.Alpha5< / version>
< scope> test< / scope>
< / dependency>
< / dependencies>
< / profile>
<个人资料>
<! - 一个可选的Arquillian测试配置文件,在远程
Wildfly实例中执行测试 - >
<! - 运行:mvn clean test -Parq-wildfly-remote - >
< id> arq-wildfly-remote< / id>
<依赖关系>
<依赖关系>
< groupId> org.wildfly.arquillian< / groupId>
< artifactId> wildfly-arquillian-container-remote< / artifactId>
< version> 1.0.0.Alpha5< / version>
< scope> test< / scope>
< / dependency>
< / dependencies>
< build>
< testResources>
< testResource>
< directory> src / test / resources< / directory>
< filtering> true< / filtering>
< / testResource>
< / testResources>
< plugins>
< plugin>
< artifactId> maven-surefire-plugin< / artifactId>
< version> 2.18.1< / version>
< / plugin>
< / plugins>
< / build>
< / profile>
<个人资料>
< id>开发< / id>
<属性>
< env>开发< / env>
< fms.restws.url> http:// localhost:8080 / fms / rs / json< /fms.restws.url>
< / properties>
< / profile>
<个人资料>
< id> prod< / id>
<属性>
< env> prod< / env>
< fms.restws.url> http:// prodserver:8080 / fms / rs / json< /fms.restws.url>
< / properties>
< / profile>
< / profiles>

GreeterTest.java

  @RunWith(Arquillian.class)public class GreeterTest {

@Inject
Greeter greeter;

@Deployment
public static Archive<?> createDeployment(){
return ShrinkWrap.create(WebArchive.class,fms-tes.war)
.addClass(Greeter.class)
.addAsManifestResource(EmptyAsset.INSTANCE,beans。 XML);
}

@Test
public void should_create_greeting()throws异常{
Assert.assertEquals(Hello,Earthling!,greeter.createGreeting(Earthling) );
greeter.greet(System.out,Earthling);
}}


解决方案

删除依赖关系管理和依赖org.wildfly的定义:wildfly-arquillian-container-embedded。您也可以使用org.wildfly.arquillian:xxxx适配器设置配置文件。它们在技术上非常相似,但适用于两个不同版本的WildFly服务器。基于相同的代码库,他们都试图注册相同的观察者。


I am trying to configure arquillian with wildfly but am the following Getting error in the process of running test:

    java.lang.RuntimeException: Could not create new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor
    at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:165).......
Caused by: java.lang.reflect.InvocationTargetException: null
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    ...........
Caused by: java.lang.RuntimeException: Could not create new instance of class org.jboss.arquillian.core.impl.ManagerImpl
    at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:165)
    at .................
Caused by: java.lang.reflect.InvocationTargetException: null
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at ...............
Caused by: java.lang.RuntimeException: Could not create and process manager
    at org.jboss.arquillian.core.impl.ManagerImpl.<init>(ManagerImpl.java:105)......
Caused by: java.lang.IllegalArgumentException: Attempted to register the same Observer: org.jboss.as.arquillian.container.ServerSetupObserver multiple times, please check classpath for conflicting jar versions
    at org.jboss.arquillian.core.impl.ManagerImpl$2.observer(ManagerImpl.java:354)
    at org.jboss.arquillian.core.impl.loadable.LoadableExtensionLoader$1.observer(LoadableExtensionLoader.java:101)
    at org.jboss.as.arquillian.container.CommonContainerExtension.register(CommonContainerExtension.java:41)
    at org.jboss.as.arquillian.container.remote.RemoteContainerExtension.register(RemoteContainerExtension.java:33)

pom.xml

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!-- maven-compiler-plugin -->
        <maven.compiler.target>1.7</maven.compiler.target>
        <maven.compiler.source>1.7</maven.compiler.source>
        <!-- build details -->
        <timestamp>${maven.build.timestamp}</timestamp>
        <maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
        <build_version>${project.version}</build_version>
        <build_number>00001</build_number>
        <!-- dependency version variables -->
        <struts2.version>2.3.24</struts2.version>
        <hibernate.version>4.3.9.Final</hibernate.version>
        <resteasy.version>3.0.11.Final</resteasy.version>
        <apache.common.version>3.3.2</apache.common.version>
        <junit-version>4.12</junit-version>
        <arquillian-version>1.1.8.Final</arquillian-version>
        <arquillian-transaction-version>1.0.1.Final</arquillian-transaction-version>
        <arquillian-wildfly-version>8.2.0.Final</arquillian-wildfly-version>
    </properties>
    <repositories>
        <repository>
            <id>JBoss Repository</id>
            <url>https://repository.jboss.org/nexus/content/groups/public/</url>
        </repository>
    </repositories>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.jboss.spec</groupId>
                <artifactId>jboss-javaee-7.0</artifactId>
                <version>1.0.0.Final</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!-- -JUNIT-->
            <dependency>
               <groupId>junit</groupId>
               <artifactId>junit</artifactId>
               <version>${junit-version}</version>
            </dependency>
            <!-- Arquillian itself-->
            <dependency>
                <groupId>org.jboss.arquillian</groupId>
                <artifactId>arquillian-bom</artifactId>
                <version>${arquillian-version}</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
            <!-- this is in an extention to arquillian it is optional-->
            <dependency>
                <groupId>org.jboss.arquillian.extension</groupId>
                <artifactId>arquillian-transaction-bom</artifactId>
                <version>${arquillian-transaction-version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!-- this is container adapter for wildfly-->
            <dependency>
               <groupId>org.wildfly</groupId>
               <artifactId>wildfly-arquillian-container-embedded</artifactId>
               <version>${arquillian-wildfly-version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <!-- Test dependencies -->
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.junit</groupId>
            <artifactId>arquillian-junit-container</artifactId>
            <version>1.1.8.Final</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.wildfly</groupId>
            <artifactId>wildfly-arquillian-container-embedded</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.extension</groupId>
            <artifactId>arquillian-transaction-jta</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.protocol</groupId>
            <artifactId>arquillian-protocol-servlet</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.weld</groupId>
            <artifactId>weld-core</artifactId>
            <version>1.1.5.Final</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.6.4</version>
            <scope>test</scope>
        </dependency>

        <!-- struts 2 dependencies -->
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>
            <version>${struts2.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-convention-plugin</artifactId>
            <version>${struts2.version}</version>
        </dependency>
        <dependency>
           <groupId>org.apache.struts</groupId>
           <artifactId>struts2-json-plugin</artifactId>
           <version>${struts2.version}</version>
        </dependency>

        <!-- Import the CDI API -->
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-cdi-plugin</artifactId>
            <version>${struts2.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.enterprise</groupId>
            <artifactId>cdi-api</artifactId>
            <version>1.2</version><!--$NO-MVN-MAN-VER$-->
        </dependency>

        <!-- Import the Common Annotations API (JSR-250) -->
        <dependency>
            <groupId>org.jboss.spec.javax.annotation</groupId>
            <artifactId>jboss-annotations-api_1.2_spec</artifactId>
        </dependency>

        <!-- Import the Servlet API -->
        <dependency>
            <groupId>org.jboss.spec.javax.servlet</groupId>
            <artifactId>jboss-servlet-api_3.1_spec</artifactId>
        </dependency>

        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
        </dependency>

        <!-- Jboss weld -->
        <dependency>
            <groupId>org.jboss.weld</groupId>
            <artifactId>weld-core</artifactId>
            <version>2.2.2.Final</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>
    <build>
      <finalName>fms</finalName>
            <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                <filtering>true</filtering>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>1.0.0.Final</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugin</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.6</version>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18.1</version>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <!-- An optional Arquillian testing profile that executes tests in your 
                Wildfly instance -->
            <!-- This profile will start a new Wildfly instance, and execute the 
                test, shutting it down when done -->
            <!-- Run with: mvn clean test -Parq-wildfly-managed -->
            <id>arq-wildfly-managed</id>
            <dependencies>
                <dependency>
                  <groupId>org.wildfly.arquillian</groupId>
                  <artifactId>wildfly-arquillian-container-managed</artifactId>
                  <version>1.0.0.Alpha5</version>
                  <scope>test</scope>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <!-- An optional Arquillian testing profile that executes tests in a remote 
                Wildfly instance -->
            <!-- Run with: mvn clean test -Parq-wildfly-remote -->
            <id>arq-wildfly-remote</id>
            <dependencies>
                <dependency>
                  <groupId>org.wildfly.arquillian</groupId>
                  <artifactId>wildfly-arquillian-container-remote</artifactId>
                  <version>1.0.0.Alpha5</version>
                  <scope>test</scope>
                </dependency>
            </dependencies>
            <build>
                <testResources>
                    <testResource>
                        <directory>src/test/resources</directory>
                        <filtering>true</filtering>
                    </testResource>
                </testResources>
                <plugins>
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.18.1</version>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>development</id>
            <properties>
                <env>development</env>
                <fms.restws.url>http://localhost:8080/fms/rs/json</fms.restws.url>
            </properties>
        </profile>
        <profile>
            <id>prod</id>
            <properties>
                <env>prod</env>
                <fms.restws.url>http://prodserver:8080/fms/rs/json</fms.restws.url>
            </properties>
        </profile>
    </profiles>

GreeterTest.java

@RunWith(Arquillian.class) public class GreeterTest {

@Inject
Greeter greeter;

@Deployment
public static Archive<?> createDeployment() {
    return ShrinkWrap.create(WebArchive.class, "fms-tes.war")
            .addClass(Greeter.class)
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}

@Test
public void should_create_greeting() throws Exception {
    Assert.assertEquals("Hello, Earthling!",greeter.createGreeting("Earthling"));
    greeter.greet(System.out, "Earthling");
} }

解决方案

Remove the dependencyManagement and dependency definition for org.wildfly:wildfly-arquillian-container-embedded. You have setup profiles using the org.wildfly.arquillian:xxxx adaptors as well. They are technically very similar but are intended for two different versions of the WildFly server. Being based on the same code base they both attempt to register the same observers.

这篇关于Arquillian:尝试多次注册同一个Observer ServerSetupObserver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆