JNDI “Cannot instantiate class: org.jboss.naming.remote.client.InitialContextFactory”

后端 未结 4 718
余生分开走
余生分开走 2021-01-12 13:05

I\'m using JBoss Server for EJB And I need JNDI in console app to get reference of session bean, console app code looks like this

import java.util.Properties         


        
4条回答
  •  轮回少年
    2021-01-12 13:50

    To overcome above error you need to pay attention to two points.
    First , You need to have jboss-client.jar in classpath.
    Second, according to Jboss version you are using you need to change your provider url.

    For JBossAS 5 you should set following properties in environment

    env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.NamingContextFactory");
    env.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
    env.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
    

    For JBossAS 7 you should set following properties in environment

    env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
    env.put(Context.PROVIDER_URL, System.getProperty(Context.PROVIDER_URL, "remote://localhost:4447"));
    env.put(Context.SECURITY_PRINCIPAL, System.getProperty("username", DEFAULT_USERNAME));
    env.put(Context.SECURITY_CREDENTIALS, System.getProperty("password", DEFAULT_PASSWORD));
    

提交回复
热议问题