Skip to content

WebLogic JNDI InitialContext configuration

In Java applications connecting to Oracle WebLogic Server, the javax.naming.InitialContext object is the entry point for accessing JNDI resources, such as EJBs. To establish this connection, the client must supply specific connection properties via a java.util.Properties object.^[weblogic-ejb.md]

Configuration properties

When initializing the context, three key properties are typically required to authenticate and connect to the WebLogic Server instance^[weblogic-ejb.md]:

  • Context.INITIAL_CONTEXT_FACTORY: Must be set to weblogic.jndi.WLInitialContextFactory to use WebLogic's JNDI service provider^[weblogic-ejb.md].
  • Context.PROVIDER_URL: Specifies the server address and port using the t3 protocol (e.g., t3://localhost:8080)^[weblogic-ejb.md].
  • Security Credentials:
    • Context.SECURITY_PRINCIPAL: The username, typically weblogic^[weblogic-ejb.md].
    • Context.SECURITY_CREDENTIALS: The password for the provided user^[weblogic-ejb.md].

Usage example

The following code demonstrates how to configure the properties and create the InitialContext^[weblogic-ejb.md]:

Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
prop.put(Context.PROVIDER_URL, "t3://localhost:8080");
prop.put(Context.SECURITY_PRINCIPAL, "weblogic");
prop.put(Context.SECURITY_CREDENTIALS, "1qaz2wsx");

InitialContext ctx = new InitialContext(prop);

Once the context is initialized, it can be used to perform JNDI lookups. For example, to retrieve a remote EJB:^[weblogic-ejb.md]

Object obj = ctx.lookup("bpm/ejb/WorkflowEngineService#core.bpm.service.workflow.engine.WorkflowEngineServiceRemote");

Sources

^[weblogic-ejb.md]