2012-02-11 32 views
0

我有這個EJB單元測試EJB和遠程接口EjbEmbedded Conatiner

@Stateless 
public class HelloBean{ 


    public String sayHello(){ 
     return "hello"; 
    } 

} 

當我這個單元測試測試:

@Test 
    public void testEmbeddedPersistence() throws NamingException { 
     assertTrue(true); 



     Map<String, Object> props = new HashMap<String, Object>(); 

     props.put(EJBContainer.MODULES, new File("target/classes")); 
     props.put("org.glassfish.ejb.embedded.glassfish.instance.root", "./src/test/resources/glassfish-testing-domain"); 

    ec = EJBContainer.createEJBContainer(props); 
    ctx = ec.getContext(); 


    String s = "java:global/classes/HelloBean"; 
    HelloBean helloBean = (HelloBean) ctx.lookup(s); 
    assertNotNull(helloBean); 

    assertABunchOfStuff();   

    ec.close(); 
} 

一切工作正常。

但是,當我將其更改爲

@Stateless 
public class HelloBean implements RemoteHello{ 


    public String sayHello(){ 
      return "hello"; 
    } 
} 

@Remote 
public interface RemoteHello{ 
    public String sayHello(); 
} 





@Test 
    public void testEmbeddedPersistence() throws NamingException { 
     assertTrue(true); 



     Map<String, Object> props = new HashMap<String, Object>(); 

     props.put(EJBContainer.MODULES, new File("target/classes")); 
     props.put("org.glassfish.ejb.embedded.glassfish.instance.root", "./src/test/resources/glassfish-testing-domain"); 

     ec = EJBContainer.createEJBContainer(props); 
     ctx = ec.getContext(); 


     String s = "java:global/classes/HelloBean!com.mycompany.remoteInterface.RemoteHello"; 
     RemoteHello remoteHello = (RemoteHello) ctx.lookup(s); 
     assertNotNull(remoteHello); 

     assertABunchOfStuff();   

     ec.close(); 
    } 

我得到一個javax.naming.NamingException中

最奇特的地方,當是的EJBContainer它intializing說:

信息:EJB5181:可移植的EJB HelloBean的JNDI名稱:[java:global/classes/HelloBean!com.mycompany.remoteInterface.RemoteHello,java:global/classes/HelloBean] Feb 10,2012 3:55:22 PM com.sun.ejb.containers .BaseContainer initializeHome

隨後不久:在錯誤

測試: testEmbeddedPersistence(com.mycompaony.HelloBean):在SerialContext [myEnv:查找失敗的全球/班/爲helloBean com.mycompany.remoteInterface.RemoteHello java的!「 = {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}

如何使用遠程接口獲得成功的jndi查找。

由於

回答

1

遠程接口不EJB精簡版(EJB 3.1規範,表27)的一部分,並且可嵌入容器僅需要提供EJB精簡版(EJB 3.1規範,第22.3.1)。