how to access the JNDI tree of the adminserver in a weblogic cluster?

时间:2018-09-18 19:49:53

标签: java-ee weblogic jndi weblogic12c java-ee-7

I have a cluster with an admin server, server 1 and server 2 the application is deployed to the cluster to server 1 and 2.

the following code works fine if I deploy the application in a local, single server

InitialContext ctx = new InitialContext(); (MBeanServer) ctx.lookup("java:comp/env/jmx/domainRuntime");

but once deployed to cluster it fails ( NamingException)

looking at the JNDI tree, I see that jmx/domainRuntime is available only in the adminserver.

so basically that is the reason of my question, how that access that resource in the adminserver if the application is in server 1 or 2.

thanks in advance.

2 个答案:

答案 0 :(得分:0)

根据https://docs.oracle.com/middleware/1213/wls/WJNDI/wls_jndi.htm#i473354,您应采用以下方法:

示例2-7在WebLogic群集中使用命名服务

Hashtable<String, String> h = new Hashtable<String, String>(7);
h.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, pURL); //For example "t3://127.0.0.1:7001"
h.put(Context.SECURITY_PRINCIPAL, pUsername);
h.put(Context.SECURITY_CREDENTIALS, pPassword);

InitialContext context = new InitialContext(h).........

您还应该参考:How to lookup JNDI resources on WebLogic?

以及其中包含的最高答案

for(int i = (int)(array.Length / 2); i < array.Length; i++)
{
    if (i % 5 == 0) // but starting at value 200 and every 5th from here
    {
        // get value
    }
    if (i % 50 == 0) // but starting from value 350 and every 50th value from here
    {
        // get value
    }
}

答案 1 :(得分:-1)

只需从您的代码中更改代码块,这将要求您导入软件包即可,这将起作用:

Environment env = new Environment();
env.setProviderUrl("localhost");
env.setSecurityPrincipal("username");
env.setSecurityCredentials("password");``
if(ctx == null) {
    try {
        ctx = env.getInitialContext();
    } catch (NamingException e) {
        System.out.println("SAML2IdentityAsserterProviderImpl: Exception " );
        e.printStackTrace();
    }
}