远程EJB调用wildfly ClassNotFoundException

时间:2018-09-28 21:20:59

标签: java ejb wildfly jndi

我很难在运行在wildfly 14上的servlet内进行EJB远程调用。它引发ClassNotFoundException:尽管我已经添加了包含所有内容的项目,但客户端似乎无法查找该接口。 EJB源,到客户端项目的构建路径。这是堆栈跟踪:

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1) javax.naming.CommunicationException: EJBCLIENT000062: Failed to look up "/OwnEjb//MyOwnBean!com.own.MyOwnBeanRemote" [Root exception is java.lang.ClassNotFoundException: com.own.MyOwnBeanRemote from [Module "deployment.OwnClient.war" from Service Module Loader]]

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at org.jboss.ejb-client@4.0.11.Final//org.jboss.ejb.client.EJBRootContext.lookupNative(EJBRootContext.java:149)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at org.wildfly.naming-client@1.0.9.Final//org.wildfly.naming.client.AbstractContext.lookup(AbstractContext.java:84)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at org.wildfly.naming-client@1.0.9.Final//org.wildfly.naming.client.WildFlyRootContext.lookup(WildFlyRootContext.java:144)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at java.naming/javax.naming.InitialContext.lookup(InitialContext.java:409)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at java.naming/javax.naming.InitialContext.lookup(InitialContext.java:409)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at deployment.OwnClient.war//com.ownClient.MyOwnClient.doGet(MyOwnClient.java:51)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at javax.servlet.api@1.0.0.Final//javax.servlet.http.HttpServlet.service(HttpServlet.java:686)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at javax.servlet.api@1.0.0.Final//javax.servlet.http.HttpServlet.service(HttpServlet.java:791)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.servlet@2.0.13.Final//io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.servlet@2.0.13.Final//io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.servlet@2.0.13.Final//io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.servlet@2.0.13.Final//io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at org.wildfly.extension.undertow@14.0.1.Final//org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.core@2.0.13.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.servlet@2.0.13.Final//io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.servlet@2.0.13.Final//io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.core@2.0.13.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.core@2.0.13.Final//io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.servlet@2.0.13.Final//io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.core@2.0.13.Final//io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.servlet@2.0.13.Final//io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.core@2.0.13.Final//io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.core@2.0.13.Final//io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.core@2.0.13.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at org.wildfly.extension.undertow@14.0.1.Final//org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.core@2.0.13.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at org.wildfly.extension.undertow@14.0.1.Final//org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.core@2.0.13.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.servlet@2.0.13.Final//io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.servlet@2.0.13.Final//io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.servlet@2.0.13.Final//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.servlet@2.0.13.Final//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.servlet@2.0.13.Final//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.servlet@2.0.13.Final//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at org.wildfly.extension.undertow@14.0.1.Final//org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at org.wildfly.extension.undertow@14.0.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at org.wildfly.extension.undertow@14.0.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at org.wildfly.extension.undertow@14.0.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at org.wildfly.extension.undertow@14.0.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1502)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.servlet@2.0.13.Final//io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.servlet@2.0.13.Final//io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.servlet@2.0.13.Final//io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.core@2.0.13.Final//io.undertow.server.Connectors.executeRootHandler(Connectors.java:360)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at io.undertow.core@2.0.13.Final//io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at org.jboss.threads@2.3.2.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at org.jboss.threads@2.3.2.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at org.jboss.threads@2.3.2.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at org.jboss.threads@2.3.2.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at java.base/java.lang.Thread.run(Thread.java:844)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1) Caused by: java.lang.ClassNotFoundException: com.own.MyOwnBeanRemote from [Module "deployment.OwnClient.war" from Service Module Loader]

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:255)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:410)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at java.base/java.lang.Class.forName0(Native Method)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at java.base/java.lang.Class.forName(Class.java:374)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     at org.jboss.ejb-client@4.0.11.Final//org.jboss.ejb.client.EJBRootContext.lookupNative(EJBRootContext.java:147)

2018-09-28 22:37:03,100 ERROR [stderr] (default task-1)     ... 48 more

我的设置如下:

客户端代码:

package com.ownClient;

import java.io.IOException;
import java.util.Hashtable;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.own.MyOwnBean;
import com.own.MyOwnBeanRemote;

@WebServlet("/test")
public class MyOwnClient extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      try {
      Properties jndiProperties = new Properties();  
      jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.ejb.client.naming.InitialContextFactory");
      jndiProperties.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");  
      jndiProperties.put("remote.connections", "default");  
      jndiProperties.put("remote.connection.default.port", "8080");  
      jndiProperties.put("remote.connection.default.host", "localhost");  
      jndiProperties.put(Context.PROVIDER_URL, "http-remoting://localhost:8080/");
      jndiProperties.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");  
      jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

      InitialContext context = new InitialContext(jndiProperties);
      MyOwnBean mB = (MyOwnBean) context.lookup("java:/OwnEjb//MyOwnBean!com.own.MyOwnBeanRemote");

      response.setContentType("text/plain");
      String res = "Message before adding message: " + mB.getMessage();
      mB.addMessage("Hi, I added you!");
      res += "\r\n Message after adding message: " + mB.getMessage();

      ServletOutputStream out = response.getOutputStream();
      out.write(res.getBytes());

    } catch (NamingException e) {
      e.printStackTrace();
    }
    }


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        doGet(request, response);
    }

}

我的maven依赖项:

<dependencies>
    <dependency>
        <groupId>jboss</groupId>
        <artifactId>jboss-client</artifactId>
        <version>4.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.jboss</groupId>
        <artifactId>jboss-remote-naming</artifactId>
        <version>2.0.4.Final</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.xnio</groupId>
        <artifactId>xnio-api</artifactId>
        <version>3.2.0.Final</version>
    </dependency>
    <dependency>
        <groupId>jboss-as-ejb-remote-server-side</groupId>
        <artifactId>jboss-as-ejb-remote-server-side</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.remoting</groupId>
        <artifactId>jboss-remoting</artifactId>
        <version>4.0.0.Final</version>
    </dependency>
  </dependencies>

是什么原因引起的问题?

提前谢谢!

1 个答案:

答案 0 :(得分:0)

我找到了解决方案:我只需要将远程接口复制到客户端的src文件夹中。事实证明,简单的构建路径还不够。