开发者

configure JNDI lookup port jboss + EJB

开发者 https://www.devze.com 2023-03-09 21:13 出处:网络
I am using JSF and EJB as two separate project in my application. Below i described code used to JNDI lookup

I am using JSF and EJB as two separate project in my application. Below i described code used to JNDI lookup

protected final Object lookup(Class className) throws NamingException {

        Properties properties = new Properties();
        properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
        properties.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
 开发者_StackOverflow       properties.put("java.naming.provider.url",ProjectConstants.PORT_NUMBER);
        initialContext = new InitialContext(properties);
        return initialContext.lookup(ProjectConstants.DEPLOYMENT_NAME+"/"+className.getSimpleName().substring(0, className.getSimpleName().lastIndexOf("Remote")) + "/remote-" + className.getName());
    }

Is there any special configuration require in jboss for port, i am used for lookup ?


By default the JNDI port is 1099. If you want another port start jBoss with -Djboss.service.binding.set=ports-01. This will add 100 to every port. 1099 -> 1199 etc.


The default port is 1099, and the context loader will attempt to do its own discovery.

However, you can also specify a port to the java.naming.provider.url, for instance this would work ust as well:

properties.put("java.naming.provider.url", "jnp://localhost:15102");

I'd also recommened you do not use hard-coded strings but rely on the existing constants in javax.naming.Context, for instance:

    final Properties    props   = new Properties();

    props.put(Context.SECURITY_PRINCIPAL, username);
    props.put(Context.SECURITY_CREDENTIALS, password);
    props.put(Context.INITIAL_CONTEXT_FACTORY, MY_JNDI_FACTORY);
    props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
    props.put(Context.SECURITY_PROTOCOL, MY_JNDI_PROTOCOL);
    props.put(Context.PROVIDER_URL, server);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号