Jboss 7中的EJB远程查找失败

时间:2016-03-07 12:55:25

标签: maven java-ee jboss jboss7.x ejb-3.0

我有以下设置: 我正在JBoss 7.1.1应用服务器中部署ROOT.war文件。

在我的ROOT.war文件中有两件事

  1. .jar文件,包含1个远程EJB(接口+实现)

  2. Spring petclinic app

  3. 在春天的petclinic应用程序中,我创建了一个控制器,唯一的puprose将调用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>
    

    我应该把它放在那里?

1 个答案:

答案 0 :(得分:2)

报告的错误是由于 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的类,它没有方法EJBClientContext.getSelector()

该方法仅在JBoss AS 7.2(EAP 6.1)上添加,如所述here,这是Wildfly的前身版本。

另一方面,引用EJBClientContext.getSelector()方法RemoteNamingStoreEJBClientHandler的类是在Wildfly 8中引入的( jboss-remote-naming-2.0.0.Final.jar ),意思是Wildfly特有的。

因此,上述错误可能是因为您必须在 pom.xml <上声明 jboss-remote-naming-2.0.1.Final.jar 作为依赖项/ em>,并将其与您的应用程序打包在一起。

正如@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>