简体   繁体   English

具有EJB配置的Java JNDI

[英]Java JNDI with EJB configuration

i have a problem with a JNDI configuration end EJB 3.1 And Oracle 12.1 DB. 我在JNDI配置结束EJB 3.1和Oracle 12.1 DB时遇到问题。 my code: 我的代码:

    private static NewSessionBeanRemote lookupRemoteSessionBean() throws NamingException {

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

    final Context context = new InitialContext(jndiProperties);
    final String appName = "";
    final String moduleName = "EjbComponent";
    final String distinctName = "";
    final String beanName = NewSessionBean.class.getSimpleName();
    final String viewClassName = NewSessionBeanRemote.class.getName();
    System.out.println("ejb:" + appName + "" + moduleName + "" + distinctName + "/" + beanName + "!" + viewClassName);
    return (NewSessionBeanRemote) context.lookup("ejb:" + appName + "" + moduleName + "" + distinctName + "/" + beanName + "!" + viewClassName);
}

ERROR when i try to lookup jndi: 当我尝试查找jndi时出错:

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:350)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at com.studio.java.client.EjbTester.lookupRemoteSessionBean(EjbTester.java:73)
at com.studio.java.client.EjbTester.invokeStatelessBean(EjbTester.java:51)
at com.studio.java.client.EjbTester.main(EjbTester.java:41)

Besides your Context.URL_PKG_PREFIXES you also need to set the following properties: 除了Context.URL_PKG_PREFIXES您还需要设置以下属性:

jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProperties.put(Context.PROVIDER_URL, "http-remoting://127.0.0.1:8080");

Also, if you have any type of authentication, you have to set it through Context.SECURITY_PRINCIPAL and Context.SECURITY_CREDENTIALS : 另外,如果您具有任何类型的身份验证,则必须通过Context.SECURITY_PRINCIPALContext.SECURITY_CREDENTIALS进行设置:

jndiProperties.put(Context.SECURITY_PRINCIPAL, "username");
jndiProperties.put(Context.SECURITY_CREDENTIALS, "password");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM