Java EJB JNDI Bean查找失败

我有以下结构:

 4.0.0 com.screening screening 1.0-SNAPSHOT pom Screening Java Parent  Module1 Module2        org.apache.maven.plugins maven-compiler-plugin 2.3.2  1.6 1.6  ${endorsed.dir}     org.apache.maven.plugins maven-ejb-plugin 2.3  3.1    org.apache.maven.plugins maven-dependency-plugin 2.1   validate  copy   ${endorsed.dir} true   javax javaee-endorsed-api 6.0 jar          

以上是pom,它是以下模块的父级:

    com.screening screening 1.0-SNAPSHOT  4.0.0 com.screening module1 1.0-SNAPSHOT ejb Module1    com.screening screening 1.0-SNAPSHOT  4.0.0 com.screening module2 1.0-SNAPSHOT ejb Module2  

我有一些无状态的bean,例如:

 @Stateless @Local public class ProcessorBean implements Processor { // implemented methods } 

我使用嵌入式EJBContainer进行Glassfish进行unit testing。 使用以下方法访问它们时:

 Processor processor = (Processor) container.getContext().lookup(new String("java:global/classes/ProcessorBean!com.screening.processor.Processor"); 

它工作正常。 问题是,当我将模块2作为模块1的一部分包含在内时,unit testing会因抛出以下exception而失败:

 javax.naming.NamingException: Lookup failed for 'java:global/classes/ProcessorBean! com.screening.processor.Processor' in SerialContext [Root exception is javax.naming.NameNotFoundException: classes] at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442) at javax.naming.InitialContext.lookup(InitialContext.java:392) at javax.naming.InitialContext.lookup(InitialContext.java:392) at com.screening.processor.ProcessorBeanTest.setUpClass(ProcessorBeanTest.java:39) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) at org.junit.runners.ParentRunner.run(ParentRunner.java:292) at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray (ReflectionUtils.java:189) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75) Caused by: javax.naming.NameNotFoundException: classes at com.sun.enterprise.naming.impl.TransientContext.resolveContext(TransientContext.java:252) at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:171) at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:172) at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup (SerialContextProviderImpl.java:58) at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:101) at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430) ... 25 more 

看看Apache Maven的类确实产生了这个。 我不知道如何解决这个问题。 这只有在我将模块2作为模块1的一部分包含在内时才会发生。

   com.screening screening 1.0-SNAPSHOT  4.0.0 com.screening module1 1.0-SNAPSHOT ejb Module1    com.screening module2 1.0-SNAPSHOT    

有任何想法吗?