当前位置: 首页 > 知识库问答 >
问题:

从Tomcat连接到JBoss 7.1.1中的EJB时,JNDI查找失败

董联
2023-03-14

有几种方法可以查找EJB

我可以通过使用此查找连接到ejb服务器,但只有在使用ConsoleClient时。

 "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName)

当我在tomcat应用程序服务器(Spring mvc项目)上尝试此查找时,此查找将不起作用。Jboss以ClassNotFoundException响应。

我假设必须有另一个jndi查找名称?不幸的是,我在网上找不到任何有用的信息。

编辑:

我的控制器

@RequestMapping(value = "login", method = RequestMethod.POST)
public LoginBeanRemote logIn(){

    final Hashtable jndiProperties = new Hashtable();
    jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

    Context context = null;
    try {
        context = new InitialContext(jndiProperties);
    } catch (NamingException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }


    final String appName = "foo_business";
    final String moduleName = "foo_business";
    final String distinctName = "";
    final String beanName = "LoginBean";

    // gesucht ist die klasse vom jboss , nicht die im frontend
    final String viewClassName = "foo.business.login.LoginBeanRemote";
    System.out.println("Looking EJB via JNDI ");
    System.out.println("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);

    try {
        return (LoginBeanRemote) context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
    } catch (NamingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;


}

我放了一个JBossEJB客户端。我的spring项目根文件夹中的属性文件

endpoint.name=foo_business//项目名称
remote.connectionprovider.create.options.org.xnio.选项。SSL_ENABLED=false
remote.connections=默认
remote.connection.default.host=127.0.0.1
remote.connection.default.port=4447
remote.connection.default.connect.options.org.xnio.选项。SASL_POLICY_NOANONYMOUS=false

LoginBean的第一部分(在JBOSS中作为JAR文件部署;

@Stateful
@Remote(LoginBeanRemote.class)
public class LoginBean implements LoginBeanRemote {

生成的EJB查找名称:

ejb:foo_business/foo_business//LoginBean!foo.business.login.LoginBeanRemote

错误:

javax.naming.NamingException: Could not load ejb proxy class recc.business.login.LoginBeanRemote [Root exception is java.lang.ClassNotFoundException: recc.business.login.LoginBeanRemote]
at org.jboss.ejb.client.naming.ejb.EjbNamingContext.createEjbProxy(EjbNamingContext.java:108)
at org.jboss.ejb.client.naming.ejb.EjbNamingContext.lookup(EjbNamingContext.java:96)
at javax.naming.InitialContext.lookup(Unknown Source)
at recc.frontend.controller.UserController.logIn(UserController.java:161)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: recc.business.login.LoginBeanRemote
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at org.jboss.ejb.client.naming.ejb.EjbNamingContext.createEjbProxy(EjbNamingContext.java:106)
    ... 36 foo

编辑:

我将ejb-project.jar添加到我的类路径中。我还将ejb包添加到我的Spring项目中,并将LoginBeanRemote放在那里。

到目前为止,项目没有响应ClassNotFound错误。当我调试创建的LoginBeanRemote时,它包括:

Proxy for remote EJB StatelessEJBLocator{appName='foo_business', moduleName='foo_business', distinctName='', beanName='LoginBean', view='interface foo.business.login.LoginBeanRemote'}

在查找期间没有例外。

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

当我尝试调用bean的函数时,它将导致异常

System.out.println(remote.helloBean());

完整消息:

   Aug 30, 2013 11:26:21 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [appServlet] in context with path [/test] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: No EJB receiver available for handling [appName:foo_business,modulename:foo_business,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@c7c0866] with root cause
java.lang.IllegalStateException: No EJB receiver available for handling [appName:foo_business,modulename:foo_business,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@c7c0866
    at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584)
    at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:119)
    at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
    at com.sun.proxy.$Proxy10.helloBean(Unknown Source)
    at foo.frontend.controller.UserController.logIn(UserController.java:167)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

编辑:我刚刚关闭了JBoss,出现了同样的错误。我认为与Jboss没有任何联系。

编辑:

我刚刚更新了我的代码:

    InitialContext context = null;
    try {
        final Properties initialContextProperties = new Properties();

        initialContextProperties.put(Context.INITIAL_CONTEXT_FACTORY,
                "org.jboss.naming.remote.client.InitialContextFactory");

        initialContextProperties.put(Context.PROVIDER_URL,
                "remote://localhost:4447");

        initialContextProperties.put(Context.URL_PKG_PREFIXES,
                "org.jboss.ejb.client.naming");

        initialContextProperties
                .put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT",
                        "false");

        initialContextProperties.put(Context.SECURITY_PRINCIPAL, "myapplicationrealmuser");
        initialContextProperties
                .put(Context.SECURITY_CREDENTIALS, "mypass");

        EJBClientConfiguration cc = new PropertiesBasedEJBClientConfiguration(
                initialContextProperties);
        ContextSelector<EJBClientContext> selector = new ConfigBasedEJBClientContextSelector(
                cc);
        EJBClientContext.setSelector(selector);

        context = new InitialContext(initialContextProperties);
    } catch (NamingException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }


    System.out.println("Looking EJB via JNDI ");

    try {

        LoginBeanRemote remote = (LoginBeanRemote) context
                .lookup("java:global/foo_business/LoginBean!foo.business.login.LoginBeanRemote");
        System.out.println(remote.helloBean());
    } catch (NamingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;

这将在查找期间返回NameNotFoundException。我尝试了各种查找名称,但都不会像这样工作。我是否缺少一些配置

错误:

javax.naming.NameNotFoundException: global/foo_business/LoginBean!foo.business.login.LoginBeanRemote -- service jboss.naming.context.java.jboss.exported.global.foo_business."LoginBean!foo.business.login.LoginBeanRemote"
    at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
    at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127)
    at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

JBOSS控制台JNDI信息:

编辑:

我将EJB部署为EAR文件,仍然收到相同的异常

javax.naming.NameNotFoundException: global/foo_business_ear-ear/foo_business_ear-ejb/LoginBean!foo.business.login.LoginBeanRemote -- service jboss.naming.context.java.jboss.exported.global.foo_business_ear-ear.foo_business_ear-ejb."LoginBean!foo.business.login.LoginBeanRemote"
    at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
    at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127)
    at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

ERROR: org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1 - Channel end notification received, closing channel Channel ID ef1b671f (outbound) of Remoting connection 6af39445 to localhost/127.0.0.1:4447

共有2个答案

冷英博
2023-03-14

我看到你提到了@状态作为你的类的注释-LoginBeanRemote。

但是,您正在尝试对无状态类进行循环-ejb:foo_business/foo_business//LoginBean!foo.business.login.LoginBeanRemote

您是否可以尝试这样放置查找-ejb:foo\u business/foo\u business//LoginBean!富。商业登录名。LoginBeanRemote**?有状态的**

这里已经解释过了

孟海
2023-03-14

作为客户端的Tomcat必须被视为不在同一应用服务器容器中运行的客户端。因此,您必须将所有相关的类/接口打包到。部署在Tomcat上的war文件。

查看堆栈跟踪:JBoss服务器确实响应,是JBoss客户端报告缺少一个类:

位于组织。jboss。ejb。客户命名。ejb。EjbNamingContext。创建EJBProxy

实际错误(缺少类)打包在NamingException中。

因此,您必须将相关类放入。Tomcat的war文件:它可能是您的远程接口。商业登录名。LoginBeanRemote。

我总是将EJB类(实现)及其接口放在两个单独的包中,EJB客户机得到一个。jar文件,其中只包含接口(可能还有异常)。所以a。包含接口和可能的异常的jar被打包到中。客户战争。

一般来说,如果独立客户端无法工作,则必须检查这些项目

  • jboss-client.jar在类路径中吗?
  • 远程接口是否在类路径中?
  • LaunalContext的属性是否完整?
  • JNDI名称正确吗?那个JNDI名称真的可以从客户端看到吗?

附录:LaunalContext的属性:

    final Properties initialContextProperties = new Properties();

    initialContextProperties.put(Context.INITIAL_CONTEXT_FACTORY,
            "org.jboss.naming.remote.client.InitialContextFactory");

    initialContextProperties.put(Context.PROVIDER_URL,
            "remote://localhost:4447");

    initialContextProperties.put(Context.URL_PKG_PREFIXES,
            "org.jboss.ejb.client.naming");

    // See .../jboss-7/standalone/configuration/application-users.properties
    initialContextProperties.put(Context.SECURITY_PRINCIPAL, "user");
    initialContextProperties.put(Context.SECURITY_CREDENTIALS, "password");

我已经测试了这些设置,JBoss AS7 JNDI证实了这一点

相关:JBoss AS7 JNDI参考

 类似资料:
  • 问题:似乎无法通过spring在Webphsere服务器中执行jndi查找EJB3。一直找不到我的jndi名称。我看不出我做错了什么。对于Websphere,您是否必须为jndi名称查找添加不同的内容? 堆栈溢出参考问题-EJB3注入Springbean 版本: Spring版本:4.1.2 WebSphereServer版本:7.0.0.27 Spring错误: 创建名为'myLocalEjb'

  • 如果有人能帮助我纠正代码中的问题,我将不胜感激。不知道我哪里错了。 当前我的persistence.xml包含

  • 问题内容: 我正在使用带有标准MySQL连接器API的Jetty 9.2(嵌入式),并且对应该如何设置它感到非常困惑。目前,我的 web.xml 文件中包含以下内容: …这在我的jetty-env.xml中: …然后执行以下代码初始化: 当我尝试启动服务器时,出现错误。我已经在代码初始化中尝试了许多不同的字符串变体,例如删除了对对象的调用,但是我只是不断地获得相同错误的变体,只是值不同。 这两个x

  • 在查找jdbc数据源的JNDI连接时,我遇到以下错误: javax。命名。ConfigurationException:无法完成“java:”名称上的JNDI操作,因为服务器运行时无法将该操作的线程与任何J2EE应用程序组件关联。当使用“java:”名称的JNDI客户端未在服务器应用程序请求的线程上执行时,可能会出现这种情况。确保J2EE应用程序不会在静态代码块或该J2EE应用程序创建的线程中对“

  • 我在WebSphere 8.5上部署了一个Java应用程序作为EAR。我试图弄清楚如何从ejb-jar.xml.(Noob到EJB)进行JNDI查找。我通常通过在WAR中添加条目来从WAR中进行JNDI条目查找web.xml.现在在ejb模块上工作,我发现我仍然可以在ejb bean[1]上进行JNDI查找。请看下面我的ejb-jar.xml: < br >我的问题是:现在我没有web.xml,如

  • 我使用的是WildFly 8.1.0最终版本。 我的应用程序是一个部署在WAR中的JavaEE web应用程序(没有EJB模块.ear)。 我想使用JNDI以编程方式调用带有他的名字的本地EJB。 EJB只是用@无状态注释(没有本地或远程接口) 我尝试以下功能: 但它不起作用(显然是针对远程EJB的) 但我没有找到任何与WildFly发生战争的本地EJB示例,我也不知道该怎么做,我不经常使用JND