Urr*_*rr4 5 jboss ejb java-ee wildfly
我目前的问题一般是,我的机器上运行了两个Wildfly 8.2.0Final实例.我知道,有类似的问题,但它们都没有真正帮助解决我的问题.其中一个包含一个restful应用程序,SenderBean它在收到GET时触发无状态会话bean .之后,这个无状态会话bean应该从远程无状态会话bean调用一个方法,该bean PrintBean位于另一个wildfly实例上.
我将首先解释一下到目前为止我所做的事情(也许我错过了一些东西,我对Java EE和Wildfly来说很新).
我会打电话给Wildfly实例与SenderBean在Sender和一个用PrintBean了Receiver.
我创建了一个名为应用程序的用户Stefan使用密码stefan,属于组guest上Receiver.在Sender,在standalone-full.xml,我通过推出添加了一个安全领域
<security-realm name="ejb-security-realm">
<server-identities>
<secret value="c3R1ZmFu"/>
</server-identities>
</security-realm>
Run Code Online (Sandbox Code Playgroud)
进入该<security-realms>部分.我还通过put添加了一个outbound-socket-binding
<outbound-socket-binding name="remote-ejb">
<remote-destination host="localhost" port="8080"/>
</outbound-socket-binding>
Run Code Online (Sandbox Code Playgroud)
进入该<socket-binding-group ...>部分.最后,我通过put创建了一个出站连接
<outbound-connections>
<remote-outbound-connection name="remote-ejb-connection" outbound-socket-binding-ref="remote-ejb" username="Stefan" security-realm="ejb-security-realm">
<properties>
<property name="SASL_POLICY_NOANONYMOUS" value="false"/>
<property name="SSL_ENABLED" value="false"/>
</properties>
</remote-outbound-connection>
</outbound-connections>
Run Code Online (Sandbox Code Playgroud)
进入该<subsystem xmlns="urn:jboss:domain:remoting:2.0">部分.
我Sender使用CLI命令standalone.bat -c standalone-full.xml -Djboss.socket.binding.port-offset=100 -Djboss.node.name=Sender和Receiverwith启动standalone.bat -c standalone-full.xml -Djboss.node.name=Receiver.
其上的Local Stateless Session Bean Sender称为SenderBean:
@Stateless
public class SenderBean implements SenderService {
private static final Logger logger = Logger.getLogger(SenderBean.class.getSimpleName());
public void send(){
logger.info("Trying to invoke");
this.invoke();
}
private void invoke() {
Properties clientProperties = new Properties();
clientProperties.put("remote.connections", "default");
clientProperties.put("remote.connection.default.port", "8080");
clientProperties.put("remote.connection.default.host", "localhost");
Properties properties = new Properties();
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
try {
Context context = new InitialContext(properties);
context = new InitialContext(properties);
Object x = context.lookup("ejb:baseproject-ear-01.00.00-SNAPSHOT/testdomain-service-01.00.00-SNAPSHOT/Receiver/PrintBean!com.schubert.baseproject.testdomain.service.PrintService");
logger.info("Obtained some object "+x.toString());
logger.info("Trying to cast.");
PrintService s = (PrintService) x;
logger.info("Cast successful");
logger.info("Printing using remote ejb: "+s.print("Markus"));
} catch (NamingException e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
并Receiver包含PrintBean:
@Stateless
@Remote(PrintService.class)
public class PrintBean implements PrintService {
@Override
public String print(String name) {
return "Hello " + name;
}
}
Run Code Online (Sandbox Code Playgroud)
现在的问题是,我总是得到一个IllegalStateException说EJBCLIENT000025:没有EJB接收器可用于处理......
我可能做错了吗?我是EJB和Wildfly的新手.您可以在GitHub上找到项目设置.
您应该将文件 jboss-ejb-client.xml 添加到发送方 EAR(而不是 WAR)。将其放在 application.xml 旁边。
jboss-ejb-client.xml内容:
<jboss-ejb-client>
<client-context>
<ejb-receivers>
<remoting-ejb-receiver outbound-connection-ref="remote-ejb-connection"/>
</ejb-receivers>
</client-context>
</jboss-ejb-client>
Run Code Online (Sandbox Code Playgroud)
在发送方 bean 中,两行就足够了:
Context context = new InitialContext();
Object x = context.lookup("ejb:baseproject-ear-01.00.00-SNAPSHOT/testdomain-service-01.00.00-SNAPSHOT/PrintBean!com.schubert.baseproject.testdomain.service.PrintService");
Run Code Online (Sandbox Code Playgroud)
请注意,我从路径中删除了“Receiver/”。您可以在服务器日志中找到 JNDI 绑定。