java.lang.NoSuchMethodError: org.jboss.ejb.client.EJBClientContext.registerEJBClientContextListener(Lorg/jboss/ejb/client/EJBClientContextListener;)Z

java.lang.NoSuchMethodError: org.jboss.ejb.client.EJBClientContext.registerEJBClientContextListener(Lorg/jboss/ejb/client/EJBClientContextListener;)Z

我在 jboss-eap-6.3 中部署了一个会话 bean,当调用 getEmployeeById(int) 方法时,它 returns 一个员工对象。

我正在通过远程客户端调用它(使用的依赖项:jboss-as-ejb-client-bom)。虽然它 returns 是预期的结果,但它在结果之前给出了 java.lang.NoSuchMethodError: 异常。此异常背后的原因是什么。

完整的控制台输出:

 Looking EJB via JNDI 
    ejb:/OMS_POC_1//EmployeeManagerImpl!com.test.oms.facade.EmployeeManager
    log4j: reset attribute= "false".
    log4j: Threshold ="null".
    log4j: Level value for root is  [DEBUG].
    log4j: root level set to DEBUG
    log4j: Class name: [org.apache.log4j.ConsoleAppender]
    log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
    log4j: Setting property [conversionPattern] to [%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n].
    log4j: Adding appender named [console] to category [root].
    2015-02-09 09:53:31 DEBUG logging:48 - Logging Provider: org.jboss.logging.Log4jLoggerProvider
    2015-02-09 09:53:31 INFO  client:42 - JBoss EJB Client version 1.0.5.Final
    2015-02-09 09:53:31 DEBUG EJBClientPropertiesLoader:101 - Looking for jboss-ejb-client.properties using classloader sun.misc.Launcher$AppClassLoader@221a5d08
    2015-02-09 09:53:31 DEBUG EJBClientPropertiesLoader:105 - Found jboss-ejb-client.properties using classloader sun.misc.Launcher$AppClassLoader@221a5d08
    2015-02-09 09:53:31 DEBUG PropertiesBasedEJBClientConfiguration:177 - endpoint.create.options. has the following options {}
    2015-02-09 09:53:31 DEBUG PropertiesBasedEJBClientConfiguration:177 - remote.connectionprovider.create.options. has the following options {org.xnio.Options.SSL_ENABLED=>false}
    2015-02-09 09:53:31 DEBUG PropertiesBasedEJBClientConfiguration:177 - remote.connection.default.connect.options. has the following options {org.xnio.Options.SASL_POLICY_NOANONYMOUS=>false}
    2015-02-09 09:53:31 DEBUG PropertiesBasedEJBClientConfiguration:177 - remote.connection.default.channel.options. has the following options {}
    2015-02-09 09:53:31 DEBUG PropertiesBasedEJBClientConfiguration:412 - Connection org.jboss.ejb.client.PropertiesBasedEJBClientConfiguration$RemotingConnectionConfigurationImpl@79929190 successfully created for connection named default
    2015-02-09 09:53:31 DEBUG PropertiesBasedEJBClientConfiguration:230 - No clusters configured in properties
    2015-02-09 09:53:31 DEBUG EJBClientContext:112 - EJB client context initializer org.jboss.ejb.client.TransactionRecoveryContextInitializer@6a3d899a failed to initialize context org.jboss.ejb.client.EJBClientContext@6e1513f3
    java.lang.NoSuchMethodError: org.jboss.ejb.client.EJBClientContext.registerEJBClientContextListener(Lorg/jboss/ejb/client/EJBClientContextListener;)Z
        at org.jboss.ejb.client.TransactionRecoveryContextInitializer.initialize(TransactionRecoveryContextInitializer.java:36)
        at org.jboss.ejb.client.EJBClientContext.init(EJBClientContext.java:110)
        at org.jboss.ejb.client.EJBClientContext.create(EJBClientContext.java:164)
        at org.jboss.ejb.client.EJBClientContext.create(EJBClientContext.java:145)
        at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.<init>(ConfigBasedEJBClientContextSelector.java:70)
        at org.jboss.ejb.client.EJBClientContext.<clinit>(EJBClientContext.java:77)
        at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:120)
        at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
        at com.sun.proxy.$Proxy0.getEmployeeById(Unknown Source)
        at com.test.rmi.RMIClient.main(RMIClient.java:29)
    2015-02-09 09:53:31 INFO  xnio:63 - XNIO Version 3.0.3.GA
    2015-02-09 09:53:31 INFO  nio:55 - XNIO NIO Implementation Version 3.0.3.GA
    2015-02-09 09:53:31 INFO  remoting:70 - JBoss Remoting version 3.2.3.GA
    2015-02-09 09:53:31 DEBUG nio:88 - Started channel thread 'Remoting "client-endpoint" write-1', selector sun.nio.ch.WindowsSelectorImpl@3c41068b
    2015-02-09 09:53:31 DEBUG nio:88 - Started channel thread 'Remoting "client-endpoint" read-1', selector sun.nio.ch.WindowsSelectorImpl@5114ae94
    2015-02-09 09:53:32 DEBUG RemotingConnectionEJBReceiver:145 - Channel Channel ID b56abf2c (outbound) of Remoting connection 30ec6243 to localhost/127.0.0.1:4447 opened for context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@6e1513f3, receiver=Remoting connection EJB receiver [connection=Remoting connection <7669929e>,channel=jboss.ejb,nodename=isurug]} Waiting for version handshake message from server
    2015-02-09 09:53:32 INFO  VersionReceiver:101 - Received server version 2 and marshalling strategies [river]
    2015-02-09 09:53:32 INFO  RemotingConnectionEJBReceiver:162 - Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@6e1513f3, receiver=Remoting connection EJB receiver [connection=Remoting connection <7669929e>,channel=jboss.ejb,nodename=isurug]} on channel Channel ID b56abf2c (outbound) of Remoting connection 30ec6243 to localhost/127.0.0.1:4447
    2015-02-09 09:53:32 DEBUG RemotingConnectionEJBReceiver:427 - Received module availability report for 1 modules
    2015-02-09 09:53:32 DEBUG RemotingConnectionEJBReceiver:429 - Registering module EJBModuleIdentifier{appName='', moduleName='OMS_POC_1', distinctName=''} availability for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@6e1513f3, receiver=Remoting connection EJB receiver [connection=Remoting connection <7669929e>,channel=jboss.ejb,nodename=isurug]}
    2015-02-09 09:53:32 DEBUG ConfigBasedEJBClientContextSelector:142 - Registered 1 remoting EJB receivers for EJB client context org.jboss.ejb.client.EJBClientContext@6e1513f3
    2015-02-09 09:53:32 WARN  ChannelAssociation:392 - Unsupported message received with header 0xffffffff
    2015-02-09 09:53:32 DEBUG EJBClientContext:557 - org.jboss.ejb.client.RandomDeploymentNodeSelector@6b29ca81 deployment node selector selected isurug node for appname=,modulename=OMS_POC_1,distinctname=
    _______[ {Name: test}, {Age: 87}, {Description: tesfgsgs} ]
    2015-02-09 09:53:32 DEBUG AutoConnectionCloser:91 - Closing Remoting connection <7669929e>
    2015-02-09 09:53:32 INFO  ChannelAssociation:370 - Channel Channel ID b56abf2c (outbound) of Remoting connection 30ec6243 to localhost/127.0.0.1:4447 can no longer process messages
    2015-02-09 09:53:32 DEBUG ChannelAssociation:105 - Closing channel Channel ID b56abf2c (outbound) of Remoting connection 30ec6243 to localhost/127.0.0.1:4447
    2015-02-09 09:53:32 DEBUG ChannelAssociation:336 - Registering a re-connect handler org.jboss.ejb.client.remoting.EJBClientContextConnectionReconnectHandler@4a776482 for broken channel Channel ID b56abf2c (outbound) of Remoting connection 30ec6243 to localhost/127.0.0.1:4447 in EJB client context org.jboss.ejb.client.EJBClientContext@6e1513f3
    2015-02-09 09:53:32 DEBUG RemotingConnectionEJBReceiver:141 - Closing channelChannel ID b56abf2c (outbound) of Remoting connection 30ec6243 to localhost/127.0.0.1:4447
    2015-02-09 09:53:32 DEBUG AutoConnectionCloser:91 - Closing endpoint "client-endpoint" <5a5dae04>

以下是远程客户端代码:

/**
 *
 */
package com.test.rmi;

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.test.oms.facade.EmployeeManager;
import com.test.oms.facade.EmployeeManagerImpl;

public class RMIClient {

    public static void main(String[] args) {

        try {
            EmployeeManager manager = lookupRemoteEJB();
            System.out.println("_______"
                    + manager.getEmployeeById(3).toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    private static EmployeeManager lookupRemoteEJB() throws NamingException {
        final Hashtable jndiProperties = new Hashtable();
        jndiProperties.put(Context.URL_PKG_PREFIXES,
                "org.jboss.ejb.client.naming");

        final Context context = new InitialContext(jndiProperties);

        final String appName = "";
        final String moduleName = "OMS_POC_1";
        final String distinctName = "";
        final String beanName = EmployeeManagerImpl.class.getSimpleName();
        final String viewClassName = EmployeeManager.class.getName();

        System.out.println("Looking EJB via JNDI ");
        System.out.println("ejb:" + appName + "/" + moduleName + "/"
                + distinctName + "/" + beanName + "!" + viewClassName);

        return (EmployeeManager) context.lookup("ejb:" + appName + "/"
                + moduleName + "/" + distinctName + "/" + beanName + "!"
                + viewClassName);

    }
}

更新:

以下是我的 pom.xml

jboss-as-ejb-client-bom 的 Maven 依赖项
<dependency>
        <groupId>org.jboss.as</groupId>
        <artifactId>jboss-as-ejb-client-bom</artifactId>
        <version>7.1.1.Final</version>
        <type>pom</type>
</dependency>

正如 Federico 在上面的评论中提到的,我遵循 link 并将 settings.xml 添加到 M2_HOME。但是版本 7.1.1.Final-redhat-1 无法运行,因为它会导致构建失败。以下依赖对我有用。

  <dependency>
        <groupId>org.jboss.as</groupId>
        <artifactId>jboss-as-ejb-client-bom</artifactId>
        <version>7.4.0.Final-redhat-19</version>
        <type>pom</type>
        <scope>import</scope>
    </dependency>