我有许多使用“arquillian-glassfish-embedded-3.1”容器(1.0.0.CR3)使用Arquillian(1.0.2.Final)运行的测试类。
如果我单独运行任何测试类,它们会按预期运行,如果我尝试运行多个测试类 (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 进入类 com.dcp.transmission.TransmissionManagerBeanTest: 在 SerialContext[myEnv={java.naming.factory.初始=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:尝试注入远程 ejb-ref name=PackageManagerBean,远程 3.x 接口=com.dcp.pkg.PackageManager 解析为应用内 EJB 的异常模块测试中的 PackageManagerBean,ejb-link=PackageManagerBean,lookup=,mappedName=,jndi-name=PackageManagerBean,refType=Session 进入类 com.dcp.transmission.TransmissionManagerBeanTest:在 SerialContext 中查找 'java:comp/env/PackageManagerBean' 失败[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory,java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl,java。命名.factory.url.pkgs=com.sun.enterprise.naming}
原因:javax.naming.NamingException:在 SerialContext [myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming 中查找“java:comp/env/PackageManagerBean”失败.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [根异常是 javax.naming.NamingException: Exception为 'Remote ejb-ref name=PackageManagerBean,Remote 3.x interface =com.dcp.pkg.PackageManager 解析 Ejb 在模块测试中解析为应用内 EJB PackageManagerBean,ejb-link=PackageManagerBean,lookup=,mappedName=,jndi-名称=PackageManagerBean,refType=Session' 。用于查找的实际(可能是内部)远程 JNDI 名称是 'PackageManagerBean#com.dcp.pkg.PackageManager' [根异常是 javax.naming.NamingException:
引起:javax.naming.NamingException: Exception resolve Ejb for 'Remote ejb-ref name=PackageManagerBean,Remote 3.x interface =com.dcp.pkg.PackageManager 在模块测试中解析为应用内 EJB PackageManagerBean,ejb-link= PackageManagerBean,lookup=,mappedName=,jndi-name=PackageManagerBean,refType=Session' 。用于查找的实际(可能是内部)远程 JNDI 名称是“PackageManagerBean#com.dcp.pkg.PackageManager”[根异常是 javax.naming.NamingException:在 SerialContext 中查找“PackageManagerBean#com.dcp.pkg.PackageManager”失败[ 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。
原因:javax.naming.NamingException:在 SerialContext [myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java 中查找 'PackageManagerBean#com.dcp.pkg.PackageManager' 失败.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [根异常是 javax.naming.NamingException :远程业务接口com.dcp.pkg.PackageManager的ejb ref解析错误[根异常是java.lang.IllegalArgumentException:参数类型不匹配]]
原因:javax.naming.NamingException:远程业务接口com.dcp.pkg.PackageManager的ejb ref解析错误[根异常是java.lang.IllegalArgumentException:参数类型不匹配]
引起:java.lang.IllegalArgumentException:参数类型不匹配
包管理器 Bean 定义如下:
@Stateless(mappedName = "PackageManagerBean")
@Remote({ PackageManager.class })
@Local({ PackageManagerLocal.class })
public class PackageManagerBean implements PackageManager {
}
包管理器被注入到几个测试类中,如下例所示:
@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 的问题。
有谁知道问题是什么以及我如何才能让它工作?