我正在查找并调用从另一个WildFly服务器实例部署在WildFly服务器(目标服务器)实例上的EJB。要做到这一点,我正在关注链接 - “https://docs.jboss.org/author/display/WFLY9/Developer+Guide#DeveloperGuide-EJBinvocationsfromaremoteserver”
test.jar已部署在目标服务器上。以下是部署日志。
16:34:46,545 INFO [org.jboss.weld.deployer] (MSC service thread 1-6) WFLYWELD0010: Stopping weld service for deployment test.jar
16:34:46,569 INFO [org.jboss.as.server.deployment] (MSC service thread 1-7) WFLYSRV0028: Stopped deployment test.jar (runtime-name: test.jar) in 40ms
16:34:46,573 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0027: Starting deployment of "test.jar" (runtime-name: "test.jar")
16:34:46,588 INFO [org.jboss.weld.deployer] (MSC service thread 1-5) WFLYWELD0003: Processing weld deployment test.jar
16:34:46,595 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-5) JNDI bindings for session bean named TestHelperBean in deployment unit deployment "test.jar" are as follows:
java:global/test/TestHelperBean!moc.test.ejb.session.TestHelperLocal
java:app/test/TestHelperBean!moc.test.ejb.session.TestHelperLocal
java:module/TestHelperBean!moc.test.ejb.session.TestHelperLocal
java:global/test/TestHelperBean!moc.test.ejb.session.TestHelperRemote
java:app/test/TestHelperBean!moc.test.ejb.session.TestHelperRemote
java:module/TestHelperBean!moc.test.ejb.session.TestHelperRemote
java:jboss/exported/test/TestHelperBean!moc.test.ejb.session.TestHelperRemote
16:34:46,610 INFO [org.jboss.weld.deployer] (MSC service thread 1-5) WFLYWELD0006: Starting Services for CDI deployment: test.jar
16:34:46,614 INFO [org.jboss.weld.deployer] (MSC service thread 1-1) WFLYWELD0009: Starting weld service for deployment test.jar
16:34:46,834 INFO [org.jboss.as.server] (XNIO-1 task-3) WFLYSRV0016: Replaced deployment "test.jar" with deployment "test.jar"
无状态会话bean已部署在目标服务器上。
package moc.test.ejb.session;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.ejb.Local;
@Stateless
@Remote (TestHelperRemote.class)
@Local(TestHelperLocal.class)
public class TestHelperBean implements TestHelperRemote,TestHelperLocal
{
public boolean testFunction() throws Exception
{
try
{
System.out.println("[TestHelperBean][testFunction]");
}catch(Exception e)
{}
return false;
}
}
以下是调用test.jarbean实例的客户端代码。
package com.testmodule.pojo;
import java.util.Hashtable;
import javax.naming.Context;
import moc.test.ejb.session.TestHelperRemote;
public class Test {
public void getDbConnection(){
try{
final Hashtable<String, String> props = new Hashtable<String, String>();
props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); // setup the ejb: namespace URL factory
final Context context = new javax.naming.InitialContext(props); // create the InitialContext
final TestHelperRemote bean = (TestHelperRemote) context.lookup("ejb:" + "" + "/" + "test" + "/"
+ "" + "/" + "TestHelperBean" + "!" + moc.test.ejb.session.TestHelperRemote.class.getName());
bean.testFunction();
}
catch(Exception e){e.printStackTrace();}
但是在运行时发生错误
15:58:48,972 ERROR [stderr] (default task-1) java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:test, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@46e20ef9
15:58:48,973 ERROR [stderr] (default task-1) at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:774)
15:58:48,974 ERROR [stderr] (default task-1) at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)
15:58:48,974 ERROR [stderr] (default task-1) at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
15:58:48,975 ERROR [stderr] (default task-1) at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:255)
15:58:48,975 ERROR [stderr] (default task-1) at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:200)
15:58:48,976 ERROR [stderr] (default task-1) at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:183)
为什么会发生此错误?
答案 0 :(得分:1)
您的客户端(即尝试调用服务的代码)位于Wildfly实例1上,其中作为您的服务器(即部署ejb的位置)位于实例2上。假设实例1在默认端口8080上运行,而实例2正在端口8180上运行。
stackoverflow question - wildfly-to-wildfly-ejb-client-without-remote-outbound-connections有一个名为在客户端服务器上创建安全领域的部分,描述了创建“outbound-socket-binding”和“remote-outbound-”所需的各个步骤。连接。”我不确定你是否已经这样做过。如果没有此步骤,实例1上的应用程序将不知道如何连接到实例2上的服务。
如果您不想进入配置路线,可以在{{3}}上写好。这项技术对我有用,可能对您找到自己的解决方案有所帮助。使用此解决方案,您可以指定连接到第二个Wildfly实例上托管的ejb所需的服务器地址,端口(在此示例中为8180),用户名和密码。