无法在 JBoss 6.4 上查找远程 EJB3
Posted
技术标签:
【中文标题】无法在 JBoss 6.4 上查找远程 EJB3【英文标题】:Cannot lookup remote EJB3 on JBoss 6.4 【发布时间】:2018-04-08 00:52:45 【问题描述】:我需要为我的本地 ejb 做一个 ejb 测试客户端,所以这是我的 ejb 应用程序详细信息:
这是我要查找的 bean:
ServiceFacadeRemote
@Remote
public interface ServiceFacadeRemote
ServiceFacade
// ServiceFacade implementation class
@Stateless
public class ServiceFacade implements ServiceFacadeRemote,ServiceFacadeLocal
...
在 JBoss 6.4 面板的“部署”部分下,我还可以看到服务的 jndi 名称:ServiceFacade
还有部署耳朵的信息
ear name: ecommerce.ear
ejb name: ecommerce-ejb-0.0.1-SNAPSHOT.jar
我按照此链接上的指南进行操作:
https://docs.jboss.org/author/display/AS72/EJB+invocations+from+a+remote+client+using+JNDI
这是我的junit测试:
static Object lookupRemoteStatelessEjb(Class<?> clazz, Context context) throws NamingException
// The app name is the application name of the deployed EJBs. This is typically the ear name
// without the .ear suffix. However, the application name could be overridden in the application.xml of the
// EJB deployment on the server.
// Since we haven't deployed the application as a .ear, the app name for us will be an empty string
final String appName = "ecommerce";
// This is the module name of the deployed EJBs on the server. This is typically the jar name of the
// EJB deployment, without the .jar suffix, but can be overridden via the ejb-jar.xml
// In this example, we have deployed the EJBs in a jboss-as-ejb-remote-app.jar, so the module name is
// jboss-as-ejb-remote-app
final String moduleName = "ecommerce-ejb-0.0.1-SNAPSHOT";
// AS7 allows each deployment to have an (optional) distinct name. We haven't specified a distinct name for
// our EJB deployment, so this is an empty string
final String distinctName = "";
// The EJB name which by default is the simple class name of the bean implementation class
final String beanName = clazz.getSimpleName();
// the remote view fully qualified class name
final String viewClassName = clazz.getName();
// let's do the lookup
return context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
@Test
public void readService()
final Hashtable<Object,Object> jndiProperties = new Hashtable<Object,Object>();
jndiProperties.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
jndiProperties.put(InitialContext.PROVIDER_URL, "remote://localhost:4447");
jndiProperties.put("jboss.naming.client.ejb.context", true);
Context ctx;
try
ctx = new InitialContext(jndiProperties);
ServiceFacadeRemote service = (ServiceFacadeRemote)lookupRemoteStatelessEjb(ServiceFacadeRemote.class, ctx);
Assert.assertNotNull(service);
Object output = service.readService(..)
Assert.assertNotNull(output);
catch (NamingException e)
Assert.fail(e.getMessage());
上线:
Object output = service.readService(..)
我收到此错误:
java.lang.IllegalStateException: EJBCLIENT000025: 没有 EJB 接收器可用于处理 [appName:ecommerce-backend,...
更糟糕的是通过更改appName或moduleName,错误是一样的,所以我认为我正在做的事情有一个基本错误......
有什么办法吗?
更新
用这个改变调用:
ejb:ecommerce/ecommerce-ejb-0.0.1-SNAPSHOT//ServiceFacade!it.infocert.shop.facade.remote.ServiceFacadeRemote
但还是不行。
但是,下面的调用(没有 ejb: 前缀)似乎有效:
ecommerce/ecommerce-ejb-0.0.1-SNAPSHOT/ServiceFacade!it.infocert.shop.facade.remote.ServiceFacadeRemote
有什么意义???
【问题讨论】:
【参考方案1】:在lookupRemoteStatelessEjb()
beanName
默认是'bean实现的简单类名'
假设所有远程接口以FacadeRemote
结束,所有无状态类以Facade
结束,您可以编写代码
final String beanName = clazz.getSimpleName().replaceAll("Remote$","");
【讨论】:
请查看主要问题的更新以上是关于无法在 JBoss 6.4 上查找远程 EJB3的主要内容,如果未能解决你的问题,请参考以下文章
无法在 Jboss-eap-6.4 中部署 Spring Boot 应用程序
Angular 2 应用程序部署在 JBOSS 6.4 eap 上,Java 服务作为后端
Jboss (6.4 EAP) 到 WebSphere (7.x)
Jboss EAP 6.4 无法在模块中定义类 org.springframework.web.servlet.DispatcherServlet