How can I bind lookup with a String

十年热恋 提交于 2019-12-11 19:03:18

问题


My Program is package client;

import homeif.HelloWorldHome;
import remoteif.HelloWorld;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import java.awt.image.LookupOp;
import java.util.Properties;

public class HelloClient {
    public static void main(String args[]) {
        try {


            Context initialContext = new InitialContext();

            Object object = initialContext.lookup("myHelloWorld");
            HelloWorldHome home =
                    (HelloWorldHome) PortableRemoteObject.narrow(object,
                            HelloWorldHome.class);
            HelloWorld myHelloWorld = home.create();
            String message = myHelloWorld.sayHello();
            System.out.println(message);
        } catch (Exception e) {
            System.err.println(" Error : " + e);
            System.exit(2);
        }

    }
}

I am getting a javax.naming.NameNotFoundException: myHelloWorld not bound.I have tried to bind it using initialContext.bind("myHelloWorld",null); But getting a NullPointerException. My jndi.properties includes

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=jnp://localhost:1099
I have specified lookup-name myHelloWorld in ejb-jar.xml. what should I have to do to bind the lookup
In jonas-ejb-jar.xml   
  ejb-name->HelloWorld 
  jndi-name->myHelloWorld

回答1:


It seems like the JNDI name ('myHelloWorld') that you are trying to connect is incorrect. Your JNDI name should bound either in Java scope or in Global scope. If it is in Java naming scope then you should access it using java:myHelloWorld, otherwise directly. You can verify the naming scope from the Jboss Admin console. Java name sapce means, it is accessible only from the same server. Global name space means, it is accessible from any other server. You can control this using the configuration in ejb-jar.xml.

Other possibility is your bean not get deployed properly. It will show a message in server log on the startup. This message also contains the JNDI name that the bean bound. Try a server restart can see you can get this details



来源:https://stackoverflow.com/questions/24080004/how-can-i-bind-lookup-with-a-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!