名称[ejb:..]未在此上下文中绑定。无法在Wildfly中找到[ejb:]。]的根本原因javax.naming.NameNotFoundException

时间:2017-07-12 09:32:48

标签: java jboss ejb wildfly jndi

我正在尝试在远程环境中调用我的EJB,并且我使用Wildfly作为我的容器。

道歉,但这是我第一次尝试以远程方式调用EJB。

我使用下面的说明在Wildfly中调用EJB。 https://docs.jboss.org/author/display/WFLY8/EJB+invocations+from+a+remote+client+using+JNDI

但是,我在调用这些EJB时遇到错误,我不知道我的配置有什么问题。

请参阅下面的错误堆栈跟踪:

SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/Project-demo] threw exception [Request processing failed; nested exception is javax.naming.NameNotFoundException: Name [ejb: /ImageService-1.0-SNAPSHOT//GrayscaleImageServiceImpl!com.project.imageservice.ImageManipulateService] is not bound in this Context. Unable to find [ejb: ].] with root cause
javax.naming.NameNotFoundException: Name [ejb: /ImageService-1.0-SNAPSHOT//GrayscaleImageServiceImpl!com.project.imageservice.ImageManipulateService] is not bound in this Context. Unable to find [ejb: ].
    at org.apache.naming.NamingContext.lookup(NamingContext.java:820)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
    at org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)
    at javax.naming.InitialContext.lookup(InitialContext.java:417)
    at com.sketchy.remote.context.RemoteContext.lookupRemoteGrayscaleService(RemoteContext.java:30)
    at com.sketchy.controllers.ServiceController.grayscaleService(ServiceController.java:78)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)

远程服务器和客户端的界面:

public interface ImageManipulateService{
    public UploadedImage manipulate(UploadedImage img) throws IOException, Exception;
}

远程服务器中的EJB(Wildfly):

@Service
@Stateless
@Remote(ImageManipulateService.class)
public class GrayscaleImageServiceImpl implements ImageManipulateService{

    @Override
    public Object manipulate(Object img) throws IOException, Exception {
        ....
    }

}

enter image description here

客户方:

  

jboss-ejb-client.properties

remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

remote.connections=default

remote.connection.default.host = localhost
remote.connection.default.port = 9090
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

我一直在tomcat服务器(:8080)中运行我的客户端,并且我试图通过localhost:9090在Wildfly上调用EJB。 (这是正确的吗?)

  

我的maven依赖项中也包含jboss-client.jar。一世   使用的是4.0.2版。 (JBoss的客户端 - 4.0.2.jar)

我创建了一个java类,它可以调用服务查找,以便方便地调用它们。

public class RemoteContext {

    public static ImageManipulateService lookupRemoteGrayscaleService() throws NamingException {
        Hashtable jndiProperties = new Hashtable();
        jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
        Context context = new InitialContext(jndiProperties);

        String appName = "";
        String moduleName = "ImageService-1.0-SNAPSHOT";
        String distinctName = "";
        String beanName = "GrayscaleImageServiceImpl";
        String viewClassName = "com.project.imageservice.ImageManipulateService";

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

    public static ImageManipulateService lookupRemoteTimestampService() throws NamingException {
        Hashtable jndiProperties = new Hashtable();
        jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
        Context context = new InitialContext(jndiProperties);

        String appName = "";
        String moduleName = "ImageService-1.0-SNAPSHOT";
        String distinctName = "";
        String beanName = "TimestampImageServiceImpl";
        String viewClassName = "com.project.imageservice.ImageManipulateService";

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


}

2 个答案:

答案 0 :(得分:2)

你的主要问题是你使用了错误的jboss-client.jar。您选择的是JBoss 4.0.x,并且不适用于WildFly。

如果您正在使用Maven构建,那么您将在客户端应用程序中包含以下依赖项(作为war项目):

    <dependency>
        <groupId>org.wildfly</groupId>
        <artifactId>wildfly-ejb-client-bom</artifactId>
        <version>10.1.0.Final</version>
        <type>pom</type>
    </dependency>

但是,由于您似乎没有使用Maven,另一种方法是添加您将在WildFly安装的jboss-client.jar目录中找到的bin/client/。它是一个“uber-jar”,包含由上面显示的maven依赖项定义的所有内容。

一旦你解决了这个问题,你可能需要一些关于JNDI名称的帮助。我们将能够使用server.log的部署输出来修复它,它会记录所有EJB应用程序的JNDI名称。

答案 1 :(得分:1)

如果EJB部署在war中,那么JNDI名称中的应用程序名称应为 empty 。虽然您的appName变量包含空字符串,但在&#34; ejb:&#34;之后有空格字符。删除此空间,使其类似于文档:

ejb:/jboss-as-ejb-remote-app//CalculatorBean!org.jboss.as.quickstarts.ejb.remote.stateless.RemoteCalculator