我在为EJB3和wildfly运行远程客户端时遇到错误。 我的ejb看起来像波纹管。
package com.tst.ejb;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
/**
* Session Bean implementation class TestWLDFly
*/
@Stateless
@LocalBean
public class TestWLDFly implements TestWLDFlyRemote {
/**
* Default constructor.
*/
public TestWLDFly() {
// TODO Auto-generated constructor stub
}
@Override
public void TestPrint() {
// TODO Auto-generated method stub
}
}
远程接口如下
package com.tst.ejb;
import javax.ejb.Remote;
@Remote
public interface TestWLDFlyRemote {
public void TestPrint();
}
远程客户端如下......
package com.tst.ejb;
import java.util.Hashtable;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.ejb.client.ContextSelector;
import org.jboss.ejb.client.EJBClientConfiguration;
import org.jboss.ejb.client.EJBClientContext;
import org.jboss.ejb.client.PropertiesBasedEJBClientConfiguration;
import org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector;
public class EJBClient {
public static void main(String[] args) throws NamingException {
final Hashtable<String, Object> jndiProperties = new Hashtable<>();
Properties p = new Properties();
p.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
p.put("remote.connections", "one");
p.put("remote.connection.one.port", "8080");
p.put("remote.connection.one.host", "localhost");
EJBClientConfiguration cc = new PropertiesBasedEJBClientConfiguration(p);
ContextSelector<EJBClientContext> selector = new ConfigBasedEJBClientContextSelector(cc);
EJBClientContext.setSelector(selector);
Properties props = new Properties();
props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
InitialContext context = new InitialContext(props);
final String rcal = "ejb:/TSTWLDFLY/TestWLDFly!com.tst.ejb.TestWLDFlyRemote";
final TestWLDFlyRemote remote = (TestWLDFlyRemote) context.lookup(rcal);
remote.TestPrint();
}
}
Wildfly日志显示JNDI名称如下所示
java:global/TSTWLDFLY/TestWLDFly!com.tst.ejb.TestWLDFlyRemote
java:app/TSTWLDFLY/TestWLDFly!com.tst.ejb.TestWLDFlyRemote
java:module/TestWLDFly!com.tst.ejb.TestWLDFlyRemote
java:jboss/exported/TSTWLDFLY/TestWLDFly!com.tst.ejb.TestWLDFlyRemote
java:global/TSTWLDFLY/TestWLDFly!com.tst.ejb.TestWLDFly
java:app/TSTWLDFLY/TestWLDFly!com.tst.ejb.TestWLDFly
java:module/TestWLDFly!com.tst.ejb.TestWLDFly
我运行客户端时遇到异常。
Nov 19, 2015 4:46:36 PM org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 2.1.1.Final
Nov 19, 2015 4:46:36 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.3.1.Final
Nov 19, 2015 4:46:36 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.3.1.Final
Nov 19, 2015 4:46:36 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.9.Final
Nov 19, 2015 4:46:41 PM org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector setupEJBReceivers
WARN: Could not register a EJB receiver for connection to localhost:8080
java.lang.RuntimeException: Operation failed with status WAITING
at org.jboss.ejb.client.remoting.IoFutureHelper.get(IoFutureHelper.java:94)
at org.jboss.ejb.client.remoting.ConnectionPool.getConnection(ConnectionPool.java:80)
at org.jboss.ejb.client.remoting.RemotingConnectionManager.getConnection(RemotingConnectionManager.java:51)
at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:158)
at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.getCurrent(ConfigBasedEJBClientContextSelector.java:115)
at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.getCurrent(ConfigBasedEJBClientContextSelector.java:47)
at org.jboss.ejb.client.EJBClientContext.getCurrent(EJBClientContext.java:279)
at org.jboss.ejb.client.EJBClientContext.requireCurrent(EJBClientContext.java:289)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:178)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146)
at com.sun.proxy.$Proxy0.TestPrint(Unknown Source)
at com.tst.ejb.EJBClient.main(EJBClient.java:40)
Exception in thread "main" java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:TSTWLDFLY, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@5c5a1b69
at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:774)
at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)
at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:255)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:200)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:183)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146)
at com.sun.proxy.$Proxy0.TestPrint(Unknown Source)
at com.tst.ejb.EJBClient.main(EJBClient.java:40)
我尝试了所有JNDI名称。可能是我做错了什么。任何帮助表示赞赏。
答案 0 :(得分:0)
您不应使用@LocalBean
注释。它使得无法远程访问此EJB。只需删除它。