在使用Arquillian运行多个测试时尝试注入Remote ejb-ref的异常

时间:2012-10-09 18:12:12

标签: ejb-3.1 jboss-arquillian

我有许多测试类使用Arquillian(1.0.2.Final)使用' arquillian-glassfish-embedded-3.1'容器(1.0.0.CR3)。

如果我单独运行任何测试类,它们会按预期运行,如果我尝试运行多个测试类(TestSuite),我会遇到将EJB注入类中的问题。

  

java.lang.RuntimeException:无法注入成员

     

引起:java.lang.IllegalStateException:异常尝试注入远程ejb-ref name = PackageManagerBean,远程3.x接口= com.dcp.pkg.PackageManager在模块测试中解析为应用内部EJB PackageManagerBean,ejb- link = PackageManagerBean,lookup =,mappedName =,jndi-name = PackageManagerBean,refType = Session in com.dcp.transmission.TransmissionManagerBeanTest:查找失败的' java:comp / env / PackageManagerBean'在SerialContext中[myEnv = {java.naming.factory.initial = com.sun.enterprise.naming.impl.SerialInitContextFactory,java.naming.factory.state = com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs = com.sun.enterprise.naming}

     

引起:com.sun.enterprise.container.common.spi.util.InjectionException:异常尝试注入Remote ejb-ref name = PackageManagerBean,Remote 3.x interface = com.dcp.pkg.PackageManager已解析为intra -app EJB PackageManagerBean在模块测试中,ejb-link = PackageManagerBean,lookup =,mappedName =,jndi-name = PackageManagerBean,refType = Session到类com.dcp.transmission.TransmissionManagerBeanTest:查找失败了' java:comp / ENV / PackageManagerBean'在SerialContext中[myEnv = {java.naming.factory.initial = com.sun.enterprise.naming.impl.SerialInitContextFactory,java.naming.factory.state = com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs = com.sun.enterprise.naming}

     

引起:javax.naming.NamingException:查找失败的' java:comp / env / PackageManagerBean'在SerialContext中[myEnv = {java.naming.factory.initial = com.sun.enterprise.naming.impl.SerialInitContextFactory,java.naming.factory.state = com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs = com.sun.enterprise.naming} [根异常是javax.naming.NamingException:异常解析Ejb for& ejb-ref name = PackageManagerBean,Remote 3.x interface = com.dcp.pkg.PackageManager在模块测试中解析为app-app EJB PackageManagerBean,ejb-link = PackageManagerBean,lookup =,mappedName =,jndi-name = PackageManagerBean,refType = Session' 。用于查找的实际(可能是内部)远程JNDI名称是' PackageManagerBean#com.dcp.pkg.PackageManager' [根异常是javax.naming.NamingException:查找失败的' PackageManagerBean#com.dcp.pkg.PackageManager'在SerialContext中[myEnv = {java.naming.factory.initial = com.sun.enterprise.naming.impl.SerialInitContextFactory,java.naming.factory.state = com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs = com.sun.enterprise.naming} [root异常是javax.naming.NamingException:ejb远程业务的解析错误interfacecom.dcp.pkg.PackageManager [root异常是java.lang。 IllegalArgumentException:参数类型不匹配]]]]

     

引起:javax.naming.NamingException:异常解析Ejb的远程ejb-ref name = PackageManagerBean,Remote 3.x interface = com.dcp.pkg.PackageManager解析为模块内的应用程序内的EJB PackageManagerBean测试,EJB链路= PackageManagerBean,查找=,mappedName =,JNDI名称= PackageManagerBean,RefType的=会话' 。用于查找的实际(可能是内部)远程JNDI名称是' PackageManagerBean#com.dcp.pkg.PackageManager' [根异常是javax.naming.NamingException:查找失败的' PackageManagerBean#com.dcp.pkg.PackageManager'在SerialContext中[myEnv = {java.naming.factory.initial = com.sun.enterprise.naming.impl.SerialInitContextFactory,java.naming.factory.state = com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs = com.sun.enterprise.naming} [root异常是javax.naming.NamingException:ejb远程业务的解析错误interfacecom.dcp.pkg.PackageManager [root异常是java.lang。 IllegalArgumentException:参数类型不匹配]]]

     

引起:javax.naming.NamingException:' PackageManagerBean#com.dcp.pkg.PackageManager'查找失败在SerialContext中[myEnv = {java.naming.factory.initial = com.sun.enterprise.naming.impl.SerialInitContextFactory,java.naming.factory.state = com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs = com.sun.enterprise.naming} [root异常是javax.naming.NamingException:ejb远程业务的解析错误interfacecom.dcp.pkg.PackageManager [root异常是java.lang。 IllegalArgumentException:参数类型不匹配]]

     

引起:javax.naming.NamingException:远程业务接口的ejb ref resolution错误com.dcp.pkg.PackageManager [根异常是java.lang.IllegalArgumentException:参数类型不匹配]

     

引起:java.lang.IllegalArgumentException:参数类型不匹配

Package Manager Bean定义如下:

@Stateless(mappedName = "PackageManagerBean")
@Remote({ PackageManager.class })
@Local({ PackageManagerLocal.class })
public class PackageManagerBean implements PackageManager {

}

根据以下示例,将Package Manager注入到几个测试类中:

@RunWith(Arquillian.class)
public class TransmissionManagerBeanTest {

      @Deployment
      public static Archive<?> createDeployment() {
                WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war")
                                    .addPackages(true, TransmissionManager.class.getPackage(), Search.class.getPackage(), PackageManager.class.getPackage(), SiteManagerBean.class.getPackage())
                                    .addAsResource("test-persistence.xml", "META-INF/persistence.xml").addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
                return war;
      }

  @EJB
  TransmissionManager transmissionManager;

  @EJB
  PackageManager packageManager;

  @EJB
  SiteManager siteManager;

  @PersistenceContext
  EntityManager entityManager;

  @Inject
  UserTransaction userTransaction;

}

我似乎没有遇到任何其他EJB的问题。

有没有人知道问题是什么以及如何让它发挥作用?

1 个答案:

答案 0 :(得分:3)

据我所知,在每个测试类之间清理嵌入式Glassfish容器中部署的资源似乎是一个问题。此时我不知道它是Arquillian,嵌入式Glassfish容器还是导致问题的代码。

我找到了一个解决方法。通过在其自己的JVM中的每个测试类中运行,我避免了上述问题。它确实增加了额外的开销,例如而不是为所有测试类重新使用嵌入式容器,容器被拆除并为每个测试类重新启动,但它允许我一次性运行所有单元测试。

我使用maven来运行测试并使用以下maven-surefire-plugin配置来确保每个测试类都在它自己的JVM中运行:

<configuration><forkCount>1</forkCount><reuseForks>false</reuseForks>....</configuration>

对于早于2.14的maven-surefire-plugin版本,您可以使用forkMode = false