我是EJB和Geronimo服务器的新手。 我想在Geronimo Server上为EJB创建Junit POC。 但是在向无状态会话bean进行查找时,它给了我这个错误。
请在下面找到例外情况
javax.naming.NamingException: Cannot lookup '/MyStatelessSessionBeanRemote'. [Root exception is java.rmi.RemoteException: Cannot read the response from the server. The class for an object being returned is not located in this system:; nested exception is:
java.lang.ClassNotFoundException: sampleear.RemoteBusinessInterface]
at org.apache.openejb.client.JNDIContext.lookup(JNDIContext.java:240)
at javax.naming.InitialContext.lookup(InitialContext.java:363)
at test.SampleTest.setUp(SampleTest.java:44)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
我正在使用Geronimo服务器2.1,并且还在geronimo服务器中部署了EAR文件。 EAR文件已成功部署,显示在Geronimo服务器上。
请在下面找到日志
2019-07-01 14:39:46,221 INFO [config] Configuring Service(id=Default BMP Container, type=Container, provider-id=Default BMP Container)
2019-07-01 14:39:46,222 INFO [config] Configuring Service(id=Default CMP Container, type=Container, provider-id=Default CMP Container)
2019-07-01 14:39:46,222 INFO [config] Configuring app: sampleear/sample-ejb/1.0/ejb
2019-07-01 14:39:46,269 INFO [OpenEJB] Auto-deploying ejb MyStatelessSessionBean: EjbDeployment(deployment-id=sample-ejb/MyStatelessSessionBean)
2019-07-01 14:39:46,277 INFO [config] Loaded Module: sampleear/sample-ejb/1.0/ejb
2019-07-01 14:39:46,555 INFO [startup] Assembling app: /tmp/geronimo-deployer1011310413181662917.tmpdir/SampleEJB.jar
2019-07-01 14:39:46,557 ERROR [startup] Jndi(name=MyStatelessSessionBeanRemote) cannot be bound to Ejb(deployment-id=sample-ejb/MyStatelessSessionBean). Name already taken by Ejb(deployment-id=SampleEJB.jar/MyStatelessSessionBean)
2019-07-01 14:39:46,557 INFO [startup] Created Ejb(deployment-id=sample-ejb/MyStatelessSessionBean, ejb-name=MyStatelessSessionBean, container=Default Stateless Container)
2019-07-01 14:39:46,558 INFO [startup] Deployed Application(path=/tmp/geronimo-deployer1011310413181662917.tmpdir/SampleEJB.jar)
2019-07-01 14:39:46,673 INFO [SupportedModesServiceImpl] Portlet mode 'edit' not found for portletId: '/plugin.Deployment!227983155|0'
2019-07-01 14:39:46,676 INFO [XSRFHandler] Updated HTML content with XSRF JavaScript for requestURI=/console/portal//Applications/Deploy%20New
Junit-客户
public class SampleTest extends TestCase {
protected MyStatelessSessionBean remoteBusinessIntf;
public void setUp() throws Exception {
super.setUp();
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");
prop.put("java.naming.provider.url", "ejbd://127.0.0.1:4201");
// prop.put("openejb.authentication.realmName","geronimo-admin");
// prop.put("java.naming.security.principal","system");
// prop.put("java.naming.security.credentials","manager");
Context context = new InitialContext(prop);
remoteBusinessIntf = (MyStatelessSessionBean) context.lookup("MyStatelessSessionBeanRemote"); // Giving error on this.
}
public void testSaveBook() {
System.out.println("ok");
remoteBusinessIntf.sayHello("EJB");
}
}
Stateless Session Bean
package sampleear;
import javax.ejb.Remote;
import javax.ejb.Stateless;
@Stateless
public class MyStatelessSessionBean implements RemoteBusinessInterface {
public String sayHello(String name) {
return getClass().getName() + " says hello to "+ name + ".";
}
}
远程界面
package sampleear;
import javax.ejb.Remote;
@Remote
public interface RemoteBusinessInterface {
public String sayHello(String name);
}
已部署的EJB应用程序
Component Name State Commands
org.apache.geronimo.configs/mejb/2.1.4/car running Stop Restart Uninstall
org.apache.geronimo.plugins/agent/2.1.4/car running Stop Restart Uninstall
sampleear/sample-ejb/1.0/ejb running Stop Restart Uninstall
Geronimo v2.1.4
未对端口进行任何修改。使用默认端口。
Geronimo的端口详细信息
Startup completed in 31.119s seconds
Listening on Ports:
1050 0.0.0.0 CORBA Naming Service
1099 0.0.0.0 RMI Naming
1527 0.0.0.0 Derby Connector
2001 0.0.0.0 OpenEJB ORB Adapter
4201 0.0.0.0 OpenEJB Daemon
6882 0.0.0.0 OpenEJB ORB Adapter
8009 0.0.0.0 Tomcat Connector AJP AJP
8080 0.0.0.0 Tomcat Connector HTTP BIO HTTP
8443 0.0.0.0 Tomcat Connector HTTPS BIO HTTPS
9999 0.0.0.0 JMX Remoting Connector
61613 0.0.0.0 ActiveMQ Transport Connector
61616 0.0.0.0 ActiveMQ Transport Connector
我再次创建了新的Geronimo服务器并部署了EJB Application。这次没有任何部署错误。请在下面找到日志。
2019-07-02 10:28:18,242 INFO [config] Configuring Service(id=Default Stateful Container, type=Container, provider-id=Default Stateful Container)
2019-07-02 10:28:18,242 INFO [config] Configuring Service(id=Default BMP Container, type=Container, provider-id=Default BMP Container)
2019-07-02 10:28:18,242 INFO [config] Configuring Service(id=Default CMP Container, type=Container, provider-id=Default CMP Container)
2019-07-02 10:28:18,243 INFO [config] Configuring app: sampleear/sample-ejb/1.0/ejb
2019-07-02 10:28:18,275 INFO [OpenEJB] Auto-deploying ejb MyStatelessSessionBean: EjbDeployment(deployment-id=sample-ejb/MyStatelessSessionBean)
2019-07-02 10:28:18,281 INFO [config] Loaded Module: sampleear/sample-ejb/1.0/ejb
2019-07-02 10:28:18,555 INFO [startup] Assembling app: /tmp/geronimo-deployer7186189966556040174.tmpdir/SampleEJB.jar
2019-07-02 10:28:18,558 INFO [startup] Jndi(name=MyStatelessSessionBeanRemote) --> Ejb(deployment-id=sample-ejb/MyStatelessSessionBean)
2019-07-02 10:28:18,558 INFO [startup] Created Ejb(deployment-id=sample-ejb/MyStatelessSessionBean, ejb-name=MyStatelessSessionBean, container=Default Stateless Container)
2019-07-02 10:28:18,558 INFO [startup] Deployed Application(path=/tmp/geronimo-deployer7186189966556040174.tmpdir/SampleEJB.jar)
2019-07-02 10:28:18,669 INFO [SupportedModesServiceImpl] Portlet mode 'edit' not found for portletId: '/plugin.Deployment!227983155|0'
2019-07-02 10:28:18,673 INFO [XSRFHandler] Updated HTML content with XSRF JavaScript for requestURI=/console/portal//Applications/Deploy%20New