Skip to content

WebLogic JNDI remote EJB lookup with Spring

WebLogic JNDI remote EJB lookup with Spring allows a Spring application to invoke Enterprise JavaBeans (EJBs) deployed on a remote WebLogic Server instance. This is achieved by configuring Spring's JndiObjectFactoryBean with the appropriate WebLogic JNDI environment properties.^[600-developer-java-application-server-weblogic-weblogic-spring-jpa.md]

Configuration

To connect to a WebLogic Server, a JNDI environment bean must be defined to provide the connection context.^[600-developer-java-application-server-weblogic-weblogic-spring-jpa.md] This environment is then referenced by the JndiObjectFactoryBean to perform the lookup.^[600-developer-java-application-server-weblogic-weblogic-spring-jpa.md]

JNDI Environment Properties

The connection parameters are defined as properties within the Spring configuration.^[600-developer-java-application-server-weblogic-weblogic-spring-jpa.md]

Property Value Description
java.naming.factory.initial weblogic.jndi.WLInitialContextFactory Specifies the initial context factory class for WebLogic.^[600-developer-java-application-server-weblogic-weblogic-spring-jpa.md]
java.naming.provider.url t3://localhost:8080 The URL of the WebLogic Server.^[600-developer-java-application-server-weblogic-weblogic-spring-jpa.md]
java.naming.security.principal weblogic The username for authentication.^[600-developer-java-application-server-weblogic-weblogic-spring-jpa.md]
java.naming.security.credentials 1qaz2wsx The password for authentication.^[600-developer-java-application-server-weblogic-weblogic-spring-jpa.md]

Spring Bean Definition

The following XML configuration demonstrates how to define the JNDI environment and the remote EJB proxy bean.^[600-developer-java-application-server-weblogic-weblogic-spring-jpa.md]

<beans:properties id="jndiEnvironment">
    <prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
    <prop key="java.naming.provider.url">t3://localhost:8080</prop>
    <prop key="java.naming.security.principal">weblogic</prop>
    <prop key="java.naming.security.credentials">1qaz2wsx</prop>
</beans:properties>

<bean id="casualGameLottGroupSeriesServiceRemote" 
      class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" 
              value="bpm.ejb.CasualGameLottGroupSeriesService#core.bpm.service.settings.CasualGameLottGroupSeriesServiceRemote">
    </property>
    <property name="jndiEnvironment" ref="jndiEnvironment" />
</bean>
  • The jndiName property specifies the global JNDI name of the EJB, typically using the ModuleName#BeanInterface syntax.^[600-developer-java-application-server-weblogic-weblogic-spring-jpa.md]
  • The JndiObjectFactoryBean handles the retrieval of the EJB stub from the WebLogic JNDI tree.^[600-developer-java-application-server-weblogic-weblogic-spring-jpa.md]

Usage

Once configured, the remote EJB can be injected into application components just like a standard Spring bean.^[600-developer-java-application-server-weblogic-weblogic-spring-jpa.md]

@Autowired
private CasualGameLottGroupSeriesServiceRemote remoteService;

public void performRemoteCall() {
    // Invoke method on remote EJB
    remoteService.someMethod();
}

In test cases, the bean can be retrieved directly from the ApplicationContext to verify the connection and remote invocation logic.^[600-developer-java-application-server-weblogic-weblogic-spring-jpa.md]

Sources

  • 600-developer-java-application-server-weblogic-weblogic-spring-jpa.md