No EJB receiver available for handling ...
在Jboss EAP 6中,调用远程EJB时出现这个错误, 原因可能是JNDI格式写错了。EJB JNDI的格式如下:
ejb:<appName>/<moduleName>/<distinctName>/<beanName>!<viewClassName>?stateful
注意appName前是没有"/"的!如没有distinctName,留空,即连续两个”//“。
在jboss-eap-quickstarts-6.4.0.GA提供了样例代码ejb-remote:
public interface RemoteCalculator { int add(int a, int b); int subtract(int a, int b); } @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; } } public class RemoteEJBClient { public static void main(String[] args) throws Exception { // Invoke a stateless bean invokeStatelessBean(); // Invoke a stateful bean invokeStatefulBean(); } private static void invokeStatelessBean() throws NamingException { // Let's lookup the remote stateless calculator final RemoteCalculator statelessRemoteCalculator = lookupRemoteStatelessCalculator(); System.out.println("Obtained a remote stateless calculator for invocation"); // invoke on the remote calculator 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)); } // try one more invocation, this time for subtraction 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<String, String> jndiProperties = new Hashtable<String, String>(); jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); final Context context = new InitialContext(jndiProperties); return (RemoteCalculator) context.lookup("ejb:/jboss-ejb-remote-server-side/CalculatorBean!" + RemoteCalculator.class.getName()); } ... }
jboss-ejb-client.properties(放在resources根目录下)
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false remote.connections=default remote.connection.default.host=localhost remote.connection.default.port = 4447 remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
Client pom.xml
<dependencyManagement> <dependencies> <dependency> <groupId>org.jboss.spec</groupId> <artifactId>jboss-javaee-6.0</artifactId> <version>${version.jboss.spec.javaee.6.0}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.jboss.as</groupId> <artifactId>jboss-as-ejb-client-bom</artifactId> <version>${version.jboss.as}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <!-- Import the transaction spec API, we use runtime scope because we aren't using any direct reference to the spec API in our client code --> <dependency> <groupId>org.jboss.spec.javax.transaction</groupId> <artifactId>jboss-transaction-api_1.1_spec</artifactId> <scope>runtime</scope> </dependency> <!-- Import the EJB 3.1 API, we use runtime scope because we aren't using any direct reference to EJB spec API in our client code --> <dependency> <groupId>org.jboss.spec.javax.ejb</groupId> <artifactId>jboss-ejb-api_3.1_spec</artifactId> <scope>runtime</scope> </dependency> <!-- We depend on the EJB remote business interfaces of this application --> <dependency> <groupId>org.jboss.quickstarts.eap</groupId> <artifactId>jboss-ejb-remote-server-side</artifactId> <type>ejb-client</type> <version>${project.version}</version> </dependency> <!-- JBoss EJB client API jar. We use runtime scope because the EJB client API isn't directly used in this example. We just need it in our runtime classpath --> <dependency> <groupId>org.jboss</groupId> <artifactId>jboss-ejb-client</artifactId> <scope>runtime</scope> </dependency> <!-- client communications with the server use XNIO --> <dependency> <groupId>org.jboss.xnio</groupId> <artifactId>xnio-api</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.jboss.xnio</groupId> <artifactId>xnio-nio</artifactId> <scope>runtime</scope> </dependency> <!-- The client needs JBoss remoting to access the server --> <dependency> <groupId>org.jboss.remoting3</groupId> <artifactId>jboss-remoting</artifactId> <scope>runtime</scope> </dependency> <!-- Remote EJB accesses can be secured --> <dependency> <groupId>org.jboss.sasl</groupId> <artifactId>jboss-sasl</artifactId> <scope>runtime</scope> </dependency> <!-- data serialization for invoking remote EJBs --> <dependency> <groupId>org.jboss.marshalling</groupId> <artifactId>jboss-marshalling-river</artifactId> <scope>runtime</scope> </dependency> </dependencies>
例子是以jar包的形式部署到jboss中的,查看jboss日志,能查找到:
java:jboss/exported/jboss-ejb-remote-server-side/CalculatorBean!org.jboss.as.quickstarts.ejb.remote.stateless.RemoteCalculator
以jar包的形式部署,访问时写法:
context.lookup("ejb:/jboss-ejb-remote-server-side/CalculatorBean!" + RemoteCalculator.class.getName());
我将其移到ear中,改为如下写法:
context.lookup("ejb:/myear/myejb/CalculatorBean!" + RemoteCalculator.class.getName());
就出现了No EJB receiver available for handling ...,注意要去掉"/"!
注意:By default WildFly uses 8080 as the remoting port. The EJB client API uses the http port, with the http-upgrade functionality, for communicating with the server for remote invocations(unless the server is configured for some other http port)
更详细信息请参见
Invoke a Session Bean Remotely using JNDI(EAP 6)
EJB invocations from a remote client using JNDI(Wildfly 8)
Remote EJB invocations via JNDI - EJB client API or remote-naming project
相关推荐
javax.ejb.AccessLocalException.class javax.ejb.CreateException.class javax.ejb.DuplicateKeyException.class javax.ejb.EJBContext.class javax.ejb.EJBException.class javax.ejb.EJBHome.class javax.ejb....
Files contained in javax.ejb.jar: META-INF/MANIFEST.MF javax.ejb.AccessLocalException.class javax.ejb.AccessTimeout.class javax.ejb.ActivationConfigProperty.class javax.ejb.AfterBegin.class javax....
javax.ejb.EJB.class javax.ejb.EJBAccessException.class javax.ejb.EJBContext.class javax.ejb.EJBException.class javax.ejb.EJBHome.class javax.ejb.EJBLocalHome.class javax.ejb.EJBLocalObject.class javax...
- `javax.ejb.EJB`、`javax.ejb.Local`和`javax.ejb.Remote`等注解:用于标记bean的接口,指定其作用范围和远程访问方式。 - `javax.ejb.TimerService`:提供了定时任务的管理,可以在EJB中创建和管理定时器。 描述...
基于java的开发源码-一个较初级的EJB商业应用的例子.zip 基于java的开发源码-一个较初级的EJB商业应用的例子.zip 基于java的开发源码-一个较初级的EJB商业应用的例子.zip 基于java的开发源码-一个较初级的EJB商业...
Files contained in javax.ejb.jar: META-INF/MANIFEST.MF javax.ejb.AccessLocalException.class javax.ejb.AccessTimeout.class javax.ejb.ActivationConfigProperty.class javax.ejb.AfterBegin.class javax....
标题中的"org.hibernate.ejb-library-3.4.0.GA"是Hibernate Entity Beans的一个特定版本,它是Hibernate框架的一部分,专门用于处理Java Enterprise Edition (EE)环境中的持久化。Hibernate是著名的对象关系映射...
罗时飞精通EJB3.0.part01.rar罗时飞精通EJB3.0.part01.rar罗时飞精通EJB3.0.part01.rar罗时飞精通EJB3.0.part01.rar
《深入解析"agent-ejb-2.1.6.jar.zip"——Java企业级应用的关键组件》 在Java世界中,EJB(Enterprise JavaBeans)是用于构建可复用的、安全的、分布式的服务器端应用程序的重要组件。"agent-ejb-2.1.6.jar.zip"是...
H:\q\罗时飞精通EJB3.0.part08.rarH:\q\罗时飞精通EJB3.0.part08.rarH:\q\罗时飞精通EJB3.0.part08.rar
H:\q\罗时飞精通EJB3.0.part09.rarH:\q\罗时飞精通EJB3.0.part09.rar
H:\q\罗时飞精通EJB3.0.part02.rarH:\q\罗时飞精通EJB3.0.part02.rar
《Apress.Pro.EJB.3.Java.Persistence.API》这本书专注于企业级Java开发中的核心技术——EJB(Enterprise JavaBeans)3.0和Java Persistence API(JPA)。EJB是Java平台上用于构建可部署在服务器端的企业级应用的...
H:\q\罗时飞精通EJB3.0.part06.rarH:\q\罗时飞精通EJB3.0.part06.rarH:\q\罗时飞精通EJB3.0.part06.rar
H:\q\罗时飞精通EJB3.0.part07.rarH:\q\罗时飞精通EJB3.0.part07.rarH:\q\罗时飞精通EJB3.0.part07.rar
H:\q\罗时飞精通EJB3.0.part05.rarH:\q\罗时飞精通EJB3.0.part05.rar
《Apress.Pro.EJB.3.Java.Persistence.API.May.2006》是一部关于企业级JavaBeans(EJB)3.0版本的专著,主要聚焦于Java持久性API(JPA)。EJB 3.0是Java EE平台的一个重要组成部分,它极大地简化了企业级应用的开发...
《Apress.Pro.EJB.3.Java.Persistence.API》这本书深入探讨了Java企业版(EJB)3中的持久化API,即Java Persistence API(JPA)。EJB 3是Java平台企业级应用开发的重要组成部分,它提供了对数据库操作的标准化框架,...
H:\q\罗时飞精通EJB3.0.part12.rarH:\q\罗时飞精通EJB3.0.part12.rar
EJB(Enterprise JavaBeans)是Java EE(Java Platform, Enterprise Edition)平台的一部分,它是一种用于构建企业级分布式应用程序的组件模型。EJB提供了一种标准的方式来实现业务逻辑,使得开发者可以专注于业务...