EJB 远程查找在 Jboss 7 中失败
EJB Remote lookup fail in Jboss 7
我有以下设置:
我正在 JBoss 7.1.1 应用程序服务器中部署一个 ROOT.war 文件。
在我的 ROOT.war 文件中有两件事
.jar 文件,其中包含 1 个远程 EJB(接口 + 实现)
Spring 宠物诊所应用程序
在 spring petclinic 应用程序中,我创建了一个控制器,其唯一目的是调用 Remote Ejb 的方法。
这是来源:
public class ExampleController {
public void callRemoteExample() {
Hashtable<Object, Object> props = new Hashtable<Object, Object>();
props.put(INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
props.put("jboss.naming.client.ejb.context", true);
props.put(URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
props.put(PROVIDER_URL, "remote://localhost:4447");
Context remoteContext = new InitialContext(props)
ExampleService service = (ExampleService) remoteContext.lookup("/ROOT/ExampleServiceImpl!com.example.ejbremote.server.ExampleService");
service.exampleMethod();
}
}
@Remote
interface ExampleService {
void exampleMethod();
}
Jboss 启动正常,打印我的 RemoteEJB 已成功部署的确认信息:
INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-1) JNDI bindings for session bean named ExampleServiceImpl in deployment unit deployment "ROOT.war" are as follows:
java:global/ROOT/ExampleServiceImpl!com.example.ejbremote.server.ExampleService
java:app/ROOT/ExampleServiceImpl!com.example.ejbremote.server.ExampleService
java:module/ExampleServiceImpl!com.example.ejbremote.server.ExampleService
java:jboss/exported/ROOT/ExampleServiceImpl!com.example.ejbremote.server.ExampleService
java:global/ROOT/ExampleServiceImpl
java:app/ROOT/ExampleServiceImpl
java:module/ExampleServiceImpl
但是当我实际调用控制器的方法时,我在 Jboss 日志中得到了这个:
WARN [org.jboss.naming.remote.client.InitialContextFactory] (http--0.0.0.0-8080-2) EJB client integration will not be available due to a problem setting up the client context: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_79]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_79]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_79]
at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_79]
at org.jboss.naming.remote.client.InitialContextFactory.setupEJBClientContext(InitialContextFactory.java:449) [jboss-remote-naming-2.0.1.Final.jar:2.0.1.Final]
at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:142) [jboss-remote-naming-2.0.1.Final.jar:2.0.1.Final]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684) [rt.jar:1.7.0_79]
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307) [rt.jar:1.7.0_79]
at javax.naming.InitialContext.init(InitialContext.java:242) [rt.jar:1.7.0_79]
at javax.naming.InitialContext.<init>(InitialContext.java:216) [rt.jar:1.7.0_79]
at org.springframework.samples.petclinic.web.ExampleController.callRemoteExample(ExampleController.java:270) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_79]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_79]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_79]
at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_79]
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219) [org.springframework.web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) [org.springframework.web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) [org.springframework.web.servlet-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745) [org.springframework.web.servlet-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686) [org.springframework.web.servlet-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) [org.springframework.web.servlet-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) [org.springframework.web.servlet-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) [org.springframework.web.servlet-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936) [org.springframework.web.servlet-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827) [org.springframework.web.servlet-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) [org.springframework.web.servlet-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) [org.springframework.web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [org.springframework.web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_79]
Caused by: java.lang.NoSuchMethodError: org.jboss.ejb.client.EJBClientContext.getSelector()Lorg/jboss/ejb/client/ContextSelector;
at org.jboss.naming.remote.client.ejb.RemoteNamingStoreEJBClientHandler.registerEJBClientContextWithSelector(RemoteNamingStoreEJBClientHandler.java:96) [jboss-remote-naming-2.0.1.Final.jar:2.0.1.Final]
at org.jboss.naming.remote.client.ejb.RemoteNamingStoreEJBClientHandler.setupEJBClientContext(RemoteNamingStoreEJBClientHandler.java:63) [jboss-remote-naming-2.0.1.Final.jar:2.0.1.Final]
... 48 more
P.S。我只在 Jboss 7 上遇到这个问题。在最新的 Wildfly 上,一切都按预期工作。
更新
我的 pom.xml 包含这个:
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-ejb-client-bom</artifactId>
<version>8.1.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
我应该放什么?
报告的错误是由于 jar 版本冲突造成的。
您的 JBoss AS 7.1.1 的 jboss-ejb-client-1.0.5.Final.jar,存在于文件夹 jboss_dir/modules/org/jboss/ejb-client/main,包含一个名为 org.jboss.ejb.client.EJBClientContext
的 class,它没有方法 EJBClientContext.getSelector()
.
该方法仅在 JBoss AS 7.2 (EAP 6.1) 上添加,如 here 所述,这是 Wildfly 的前身版本。
另一方面,在 Wildfly 8 中引入了引用 EJBClientContext.getSelector()
方法 RemoteNamingStoreEJBClientHandler
的 class(jboss-remote -naming-2.0.0.Final.jar),意思是 Wildfly 特有的。
因此,出现上述错误可能是因为您必须将 jboss-remote-naming-2.0.1.Final.jar 声明为依赖项,在您的 pom.xml 上,并将其打包到您的应用程序中。
如@eis 所述,您应该将 jboss-as-ejb-client-bom 添加到 pom.xml。但您必须按照 提供的方式:
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-ejb-client-bom</artifactId>
<version>7.1.1.Final</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
我有以下设置: 我正在 JBoss 7.1.1 应用程序服务器中部署一个 ROOT.war 文件。
在我的 ROOT.war 文件中有两件事
.jar 文件,其中包含 1 个远程 EJB(接口 + 实现)
Spring 宠物诊所应用程序
在 spring petclinic 应用程序中,我创建了一个控制器,其唯一目的是调用 Remote Ejb 的方法。 这是来源:
public class ExampleController {
public void callRemoteExample() {
Hashtable<Object, Object> props = new Hashtable<Object, Object>();
props.put(INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
props.put("jboss.naming.client.ejb.context", true);
props.put(URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
props.put(PROVIDER_URL, "remote://localhost:4447");
Context remoteContext = new InitialContext(props)
ExampleService service = (ExampleService) remoteContext.lookup("/ROOT/ExampleServiceImpl!com.example.ejbremote.server.ExampleService");
service.exampleMethod();
}
}
@Remote
interface ExampleService {
void exampleMethod();
}
Jboss 启动正常,打印我的 RemoteEJB 已成功部署的确认信息:
INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-1) JNDI bindings for session bean named ExampleServiceImpl in deployment unit deployment "ROOT.war" are as follows:
java:global/ROOT/ExampleServiceImpl!com.example.ejbremote.server.ExampleService
java:app/ROOT/ExampleServiceImpl!com.example.ejbremote.server.ExampleService
java:module/ExampleServiceImpl!com.example.ejbremote.server.ExampleService
java:jboss/exported/ROOT/ExampleServiceImpl!com.example.ejbremote.server.ExampleService
java:global/ROOT/ExampleServiceImpl
java:app/ROOT/ExampleServiceImpl
java:module/ExampleServiceImpl
但是当我实际调用控制器的方法时,我在 Jboss 日志中得到了这个:
WARN [org.jboss.naming.remote.client.InitialContextFactory] (http--0.0.0.0-8080-2) EJB client integration will not be available due to a problem setting up the client context: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_79]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_79]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_79]
at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_79]
at org.jboss.naming.remote.client.InitialContextFactory.setupEJBClientContext(InitialContextFactory.java:449) [jboss-remote-naming-2.0.1.Final.jar:2.0.1.Final]
at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:142) [jboss-remote-naming-2.0.1.Final.jar:2.0.1.Final]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684) [rt.jar:1.7.0_79]
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307) [rt.jar:1.7.0_79]
at javax.naming.InitialContext.init(InitialContext.java:242) [rt.jar:1.7.0_79]
at javax.naming.InitialContext.<init>(InitialContext.java:216) [rt.jar:1.7.0_79]
at org.springframework.samples.petclinic.web.ExampleController.callRemoteExample(ExampleController.java:270) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_79]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_79]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_79]
at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_79]
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219) [org.springframework.web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) [org.springframework.web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) [org.springframework.web.servlet-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745) [org.springframework.web.servlet-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686) [org.springframework.web.servlet-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) [org.springframework.web.servlet-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) [org.springframework.web.servlet-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) [org.springframework.web.servlet-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936) [org.springframework.web.servlet-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827) [org.springframework.web.servlet-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) [org.springframework.web.servlet-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) [org.springframework.web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [org.springframework.web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_79]
Caused by: java.lang.NoSuchMethodError: org.jboss.ejb.client.EJBClientContext.getSelector()Lorg/jboss/ejb/client/ContextSelector;
at org.jboss.naming.remote.client.ejb.RemoteNamingStoreEJBClientHandler.registerEJBClientContextWithSelector(RemoteNamingStoreEJBClientHandler.java:96) [jboss-remote-naming-2.0.1.Final.jar:2.0.1.Final]
at org.jboss.naming.remote.client.ejb.RemoteNamingStoreEJBClientHandler.setupEJBClientContext(RemoteNamingStoreEJBClientHandler.java:63) [jboss-remote-naming-2.0.1.Final.jar:2.0.1.Final]
... 48 more
P.S。我只在 Jboss 7 上遇到这个问题。在最新的 Wildfly 上,一切都按预期工作。
更新
我的 pom.xml 包含这个:
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-ejb-client-bom</artifactId>
<version>8.1.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
我应该放什么?
报告的错误是由于 jar 版本冲突造成的。
您的 JBoss AS 7.1.1 的 jboss-ejb-client-1.0.5.Final.jar,存在于文件夹 jboss_dir/modules/org/jboss/ejb-client/main,包含一个名为 org.jboss.ejb.client.EJBClientContext
的 class,它没有方法 EJBClientContext.getSelector()
.
该方法仅在 JBoss AS 7.2 (EAP 6.1) 上添加,如 here 所述,这是 Wildfly 的前身版本。
另一方面,在 Wildfly 8 中引入了引用 EJBClientContext.getSelector()
方法 RemoteNamingStoreEJBClientHandler
的 class(jboss-remote -naming-2.0.0.Final.jar),意思是 Wildfly 特有的。
因此,出现上述错误可能是因为您必须将 jboss-remote-naming-2.0.1.Final.jar 声明为依赖项,在您的 pom.xml 上,并将其打包到您的应用程序中。
如@eis 所述,您应该将 jboss-as-ejb-client-bom 添加到 pom.xml。但您必须按照 提供的方式:
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-ejb-client-bom</artifactId>
<version>7.1.1.Final</version>
<type>pom</type>
<scope>provided</scope>
</dependency>