2017-07-27 96 views
1

我知道很多人已经问了这个错误,但我仍然无法找到我的情况,我跟着this tutorial创建一个远程客户端解决方案,访问到Bean驻留在一个Wildfly 10服务器,运行地址为:localhost:8082。这里是我的代码:没有可用的EJB接收器在创建EJB远程客户端

我的接口:

package ejb.remote.stateless; 
import javax.ejb.Remote; 

@Remote 
public interface RemoteCalculator { 
    int add(int a, int b); 
    int subtract(int a, int b); 
} 

我的豆:

package ejb.remote.stateless; 
import javax.ejb.Remote; 
import javax.ejb.Stateless; 

@Stateless 
@Remote(RemoteCalculator.class) 
public class CalculatorBean implements RemoteCalculator { 

    @Override 
    public int add(int a, int b) { 
     return a+b; 
    } 

    @Override 
    public int subtract(int a, int b) { 
     return a-b; 
    } 

} 

我的远程客户端:

package ejb.remote.client; 

import java.util.Hashtable; 

import javax.naming.Context; 
import javax.naming.InitialContext; 
import javax.naming.NamingException; 


import ejb.remote.stateful.CounterBean; 
import ejb.remote.stateful.RemoteCounter; 
import ejb.remote.stateless.CalculatorBean; 
import ejb.remote.stateless.RemoteCalculator; 

public class RemoteEJBClient { 

    public static void main(String[] args) throws NamingException { 

     // Invoke a stateless bean 
     invokeStatelessBean(); 
    } 

    /** 
    * Looks up a stateless bean and invokes on it 
    * 
    * @throws NamingException 
    */ 
    private static void invokeStatelessBean() throws NamingException { 

     final RemoteCalculator statelessRemoteCalculator = lookupRemoteStatelessCalculator(); 
     System.out.println("Obtained a remote stateless calculator for invocation"); 

     int a = 204; 
     int b = 340; 
     System.out.println("Adding " + a + " and " + b + " via the remote stateless calculator deployed on the server"); 
     int sum = statelessRemoteCalculator.add(a, b); 
     System.out.println("Remote calculator returned sum = " + sum); 
     if (sum != a + b) { 
      throw new RuntimeException(
        "Remote stateless calculator returned an incorrect sum " + sum + " ,expected sum was " + (a + b)); 
     } 

     int num1 = 3434; 
     int num2 = 2332; 
     System.out.println("Subtracting " + num2 + " from " + num1 
       + " via the remote stateless calculator deployed on the server"); 
     int difference = statelessRemoteCalculator.subtract(num1, num2); 
     System.out.println("Remote calculator returned difference = " + difference); 
     if (difference != num1 - num2) { 
      throw new RuntimeException("Remote stateless calculator returned an incorrect difference " + difference 
        + " ,expected difference was " + (num1 - num2)); 
     } 
    } 

    private static RemoteCalculator lookupRemoteStatelessCalculator() throws NamingException { 

     final Hashtable jndiProperties = new Hashtable(); 
     jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); 
     jndiProperties.put("jboss.naming.client.ejb.context", true); 

     final InitialContext context = new InitialContext(jndiProperties); 

     final String appName = ""; 

     final String moduleName = "jboss-as-ejb-remote-app"; 

     final String distinctName = ""; 

     final String beanName = CalculatorBean.class.getSimpleName(); 

     final String viewClassName = RemoteCalculator.class.getName(); 


     return (RemoteCalculator) context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName); 

    } 

} 

然后我也文件中添加jboss-ejb-client.properties到的src/文件夹中的项目,它看起来像:

remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false 

remote.connections=default 

remote.connection.default.host=localhost 
remote.connection.default.port = 8082 
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false 

做得很完全一样的教程,但我仍然得到错误:

Exception in thread "main" java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:jboss-as-ejb-remote-app, distinctName:] combination for invocation context [email protected] 
    at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:798) 
    at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:128) 
    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.add(Unknown Source) 
    at ejb.remote.client.RemoteEJBClient.invokeStatelessBean(RemoteEJBClient.java:36) 
    at ejb.remote.client.RemoteEJBClient.main(RemoteEJBClient.java:20) 

任何人都可以帮我解决这个问题吗?谢谢!

回答

0

的代码是好的。正如在本教程中提到,你必须确保jboss-ejb-client.properties文件是真正的类路径。那么它应该工作! (我甚至能够通过移动jboss-ejb-client.properties出来的类路径与同一堆栈跟踪重现您的问题)

提示:这是相当惯例(特别是Maven项目),把这些文件src/main/resources下。

欲了解更多信息请参阅github.com/wildfly/quickstart/ejb-remote,这是同一个项目中的教程。

+0

当你部署你的代码,日志给一些细节是有帮助的,比较反对什么[R你的客户正在下降你找。你的jar名为jboss-as-ejb-remote-app? –