Glassfish v3 / JNDI入门无法找到问题! [英] Glassfish v3 / JNDI entry cannot be found problems!

查看:175
本文介绍了Glassfish v3 / JNDI入门无法找到问题!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从Java应用程序客户端调用EJB的方法时遇到了问题。
这里是代码。



EJB远程接口

  package com.test; 

import javax.ejb.Remote;

@Remote
public interface HelloBeanRemote {

public String sayHello();

$ b $ / code $ / pre
$ b $ EJB

  package com.test; 

import javax.ejb.Stateless;

@Stateless(name =HelloBeanExample,mappedName =ejb / HelloBean)
public class HelloBean实现HelloBeanRemote {

@Override
public String sayHello(){

returnhola;





$ b主类(另一个项目)

  import com.test.HelloBeanRemote; 
import javax.naming.Context;
import javax.naming.InitialContext;

public class Main {


public void runTest()throws Exception {

Context ctx = new InitialContext();
HelloBeanRemote bean =(HelloBeanRemote)ctx.lookup(java:global / Test / HelloBeanExample!com.test.HelloBeanRemote);
System.out.println(bean.sayHello());



$ public static void main(String [] args)throws Exception {

Main main = new Main();
main.runTest();

}

}

是我的问题?

  java.lang.NullPointerException $ b $ com com.un.enterprise.naming .impl.SerialContext.getRemoteProvider(SerialContext.java:297)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271)
at com.sun.enterprise.naming .impl.SerialContext.lookup(SerialContext.java:430)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at testdesktop.Main.runTest(Main.java:22)$在线程main中的异常javax.naming.NamingException:在SerialContext中的'java:global / Test / HelloBeanExample!com.test.HelloBeanRemote'的查找失败[Root异常是javax.naming.NamingException:无法获取SerialContext的SerialContextProvider [根异常是java.lang.NullPointerException]]
在com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at testdesktop.Main.runTest(Main.java:22)
at testdesktop.Main.main(Main.java:31)引起:javax.naming.NamingException:无法获取SerialContext的SerialContextProvider [根异常是java.lang.NullPointerException]
在com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:276)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
... 3 more引起来自:java.lang.NullPointerException $ b $ com at com.un.enterprise .naming.impl.SerialContext.getRemoteProvider(SerialContext.java:297)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271)
... 4更多Java结果:1

我尝试了不同的JNDI条目,但没有任何效果(我从NetBeans控制台):



INFO:EJ的便携式JNDI名称B HelloBeanExample:[java:global / Test / HelloBeanExample,java:global / Test / HelloBeanExample!com.test.HelloBeanRemote]

INFO:特定于Glassfish )EJB HelloBeanExample的JNDI名称:[ejb / HelloBean,ejb / HelloBean#com.test.HelloBeanRemote]

所以我尝试了下列条目,但得到了相同的异常:
$ b $ ol

  • java:global / Test / HelloBeanExample

  • java:global / Test / HelloBeanExample!com .test.HelloBeanRemote

  • ejb / HelloBean
  • ejb / HelloBean#com.test.HelloBeanRemote



  • 我使用Netbeans 6.8和Glassfish v3!

    解决方案

    实际上,是不是查找你的bean的JNDI引用,或者你会得到类似的东西:

     导致:javax.naming.NameNotFoundException:ejb / HelloBean未找到

    不,在这里,我怀疑简单的类路径问题,您只是在客户端项目的类路径中丢失了一些jar。在GlassFish v3中,添加 $ GF_HOME / modules / gf-client.jar 应该足够了,如如何从独立java客户端访问远程EJB组件?在GlassFish的EJB常见问题解答中(我的理解是这个jar应该是以替换 $ GF_HOME / lib / appserv-rt.jar ,这是出于兼容性原因与GFv2)。然而,从GlassFish安装目录中引用 gf-client.jar 或清单中声明的​​jar无法找到是非常重要的。


    gf-client.jar 引用GlassFish安装目录中的许多其他.jar,因此最好引用从它的安装目录本身,而不是将它(和所有其他.jars)复制到另一个位置。

    一旦解决了这个问题,您应该能够使用GlassFish在日志中输出的JNDI名称来查找bean。我建议使用Java EE 6中新的可移植全局JNDI名称。



    以防万一, EJB 3.1中的可移植全局JNDI名称的语法是什么? GlassFish EJB FAQ中的条目提供了这个新的惯例。如果您想了解更多信息,请查看: http://blogs.oracle.com/MaheshKannan/entry / portable_global_jndi_names


    I've been having problems trying to call an EJB's method from a Java Application Client. Here is the code.

    EJB Remote Interface

    package com.test;
    
    import javax.ejb.Remote;
    
    @Remote
    public interface HelloBeanRemote {
    
        public String sayHello();
    
    }
    

    EJB

    package com.test;
    
    import javax.ejb.Stateless;
    
    @Stateless (name="HelloBeanExample" , mappedName="ejb/HelloBean")
    public class HelloBean implements HelloBeanRemote {
    
        @Override
        public String sayHello(){
    
            return "hola";
    
        }
    
    }
    

    Main class (another project)

    import com.test.HelloBeanRemote;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    
    public class Main {
    
    
        public void runTest()throws Exception{
    
            Context ctx = new InitialContext();
            HelloBeanRemote  bean = (HelloBeanRemote)ctx.lookup("java:global/Test/HelloBeanExample!com.test.HelloBeanRemote");
            System.out.println(bean.sayHello());
    
        }
    
    
        public static void main(String[] args)throws Exception {
    
            Main main = new Main();
            main.runTest();
    
        }
    
    }
    

    Well, what is my problem? JNDI entry for this EJB cannot be found!

    java.lang.NullPointerException
            at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:297)
            at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271)
            at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
            at javax.naming.InitialContext.lookup(InitialContext.java:392)
            at testdesktop.Main.runTest(Main.java:22)
            at testdesktop.Main.main(Main.java:31) Exception in thread "main" javax.naming.NamingException: Lookup failed for 'java:global/Test/HelloBeanExample!com.test.HelloBeanRemote' in SerialContext  [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext  [Root exception is java.lang.NullPointerException]]
            at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)
            at javax.naming.InitialContext.lookup(InitialContext.java:392)
            at testdesktop.Main.runTest(Main.java:22)
            at testdesktop.Main.main(Main.java:31) Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext  [Root exception is java.lang.NullPointerException]
            at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:276)
            at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
            ... 3 more Caused by: java.lang.NullPointerException
            at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:297)
            at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271)
            ... 4 more Java Result: 1
    

    I've trying with different JNDI entries but nothing works (I got this entries from NetBeans console):

    INFO: Portable JNDI names for EJB HelloBeanExample : [java:global/Test/HelloBeanExample, java:global/Test/HelloBeanExample!com.test.HelloBeanRemote]

    INFO: Glassfish-specific (Non-portable) JNDI names for EJB HelloBeanExample : [ejb/HelloBean, ejb/HelloBean#com.test.HelloBeanRemote]

    So I tried with the following entries but I got the same exception :

    1. java:global/Test/HelloBeanExample
    2. java:global/Test/HelloBeanExample!com.test.HelloBeanRemote
    3. ejb/HelloBean
    4. ejb/HelloBean#com.test.HelloBeanRemote

    I'm using Netbeans 6.8 and Glassfish v3!

    解决方案

    Actually, your problem is not the lookup of the JNDI reference of your bean or you would get something like that:

    Caused by: javax.naming.NameNotFoundException: ejb/HelloBean not found
    

    No, here, I suspect a simple classpath problem, you're simply missing some jar on the classpath of your client project. With GlassFish v3, adding $GF_HOME/modules/gf-client.jar should be enough as mentioned in How do I access a Remote EJB component from a stand-alone java client? in GlassFish's EJB FAQ (my understanding is that this jar is supposed to replace $GF_HOME/lib/appserv-rt.jar which is there for compatibility reasons with GFv2). It is however important to refer the gf-client.jar from the GlassFish installation directory or the jars declared in its manifest won't be found.

    gf-client.jar refers to many other .jars from the GlassFish installation directory so it is best to refer to it from within the installation directory itself rather than copying it (and all the other .jars) to another location.

    Once you'll have this fixed, you should be able to lookup your bean using the JNDI names that GlassFish outputs in the logs. I'd suggest to use the new portable global JNDI names from Java EE 6.

    Just in case, the What is the syntax for portable global JNDI names in EJB 3.1? entry from the GlassFish EJB FAQ provides a nice summary of this new convention. And if you want more information, check out: http://blogs.oracle.com/MaheshKannan/entry/portable_global_jndi_names.

    这篇关于Glassfish v3 / JNDI入门无法找到问题!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆