我尝试远程访问(eclipse)EJB-Project中的EJB,打包为jar,部署在WildFly 10.1.0 Final上。服务器端不是maven-project,所以我在java构建路径中添加了ejb-3.0.jar,javaee-api-7.0.jar,jboss-ejb3-ext-api-1.1.0.jar。
我的服务器代码是:
package org.maometto.api; public interface IMyBeanRemote { void sayHello(); }
package org.maometto.businesslogic;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import org.maometto.api.IMyBeanLocal;
import org.maometto.api.IMyBeanRemote;
@Stateless
@Remote(IMyBeanRemote.class)
public class MyBeanImpl implements IMyBeanRemote {
@Override
public void sayHello() {
System.out.println("I am Server");
}
}
当我从eclipse中启动服务器时,日志显示:
21:06:19,015 INFO [org.jboss.as.ejb3.deployment](MSC服务主题) 1-4)WFLYEJB0473:名为' MyBeanImpl'的会话bean的JNDI绑定在 部署单位'部署" MyFirstEJB.jar"'如下面所述: java:global / MyFirstEJB / MyBeanImpl!org.maometto.api.IMyBeanRemote java:app / MyFirstEJB / MyBeanImpl!org.maometto.api.IMyBeanRemote Java的:模块/ MyBeanImpl org.maometto.api.IMyBeanRemote
Java的:JBoss的/导出/ MyFirstEJB / MyBeanImpl org.maometto.api.IMyBeanRemote! java:global / MyFirstEJB / MyBeanImpl java:app / MyFirstEJB / MyBeanImpl
的java:模块/ MyBeanImpl
我的客户 - 在自己的项目代码中转换的maven项目如下:
package com.maometto.client;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.maometto.api.IMyBeanRemote;
public class EJbClient {
public static void main(String[] args) {
Properties jndiProps = new Properties();
//jndiProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProps.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
jndiProps.put("jboss.naming.client.ejb.context", true);
try {
InitialContext initialContext = new InitialContext(jndiProps);
IMyBeanRemote iMyBeanRemote = (IMyBeanRemote) initialContext.lookup("java:global/MyFirstEJB/MyBeanImpl!org.maometto.api.IMyBeanRemote");
iMyBeanRemote.sayHello();
} catch (NamingException e) {
e.printStackTrace();
}
}
}
要在客户端获取远程接口,我将ejb-project添加到客户端项目的java构建路径中。
客户的POM是:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MyEJBClient</groupId>
<artifactId>MyEJBClient</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-jms-client-bom</artifactId>
<version>10.0.0.Final</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-naming</artifactId>
<version>7.1.3.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.marshalling</groupId>
<artifactId>jboss-marshalling-river</artifactId>
<version>1.4.0.Final</version>
</dependency>
<dependency>
<groupId>jboss</groupId>
<artifactId>jbossall-client</artifactId>
<version>4.2.2.GA</version>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.1_spec</artifactId>
<version>1.0.2.Final</version>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-ejb-client</artifactId>
<version>4.0.8.Final</version>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-ejb-client-bom</artifactId>
<version>11.0.0.Final</version>
<type>pom</type>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
当我执行客户端时,我会在日志中跟踪堆栈跟踪:
javax.naming.NameNotFoundException: global/MyFirstEJB/MyBeanImpl!org.maometto.api.IMyBeanRemote -- service jboss.naming.context.java.jboss.exported.global.MyFirstEJB."MyBeanImpl!org.maometto.api.IMyBeanRemote"
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:106)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:207)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:184)
at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127)
at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
我也尝试了其他的jndiBindings。
我也尝试过&#34; ejb:&#34;命名空间及其约定(&#34; ejb:&#34; + appName +&#34; /&#34; + moduleName +&#34; /&#34; + distinctName +&#34; /&#34 ; + beanName +&#34;!&#34; + viewClassName)。还是一样的错误。我不知道自己错过了什么,或者我做错了什么。
有人可以帮助我吗?