Developing Applications with WebLogic Server

     Previous  Next    Open TOC in new window  Open Index in new window  View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Spring Applications Reference

The following sections describe developing and managing Spring Framework-based applications for WebLogic Server. In most cases, the information in these sections is described from the perspective of creating MedRec-Spring.


About Spring on WebLogic Server

To demonstrate the ways in which Spring can take advantage of WebLogic Server’s enterprise features, BEA redesigned the Avitek Medical Records sample application (MedRec) to replace core J2EE components with Spring components. For additional information on MedRec architecture and its redesign see the article "Spring 2.0.1 and BEA WebLogic Server 9.2 Integration" at

The following sections describe key steps that BEA performed when redesigning MedRec. You can use this information if you want to redesign your own J2EE-based WebLogic Server applications to use Spring components. You can also leverage this information if you want to create a new application, based on Spring components, for WebLogic Server.

It is assumed that you are familiar with J2EE concepts, WebLogic Server, and the Spring Framework. For information on WebLogic Server, see BEA WebLogic Server 10.0 Documentation. For information about Spring on the BEA dev2dev Web site, see Spring Resource Page. For information on the Spring Framework in general, see


Redesigning a J2EE-Based Application to a Spring-Based Application

To transform a J2EE-based application to a Spring-based application, you perform the following steps as desired:

  1. Configure Spring Inversion of Control.
  2. Enable the Spring Web Services Client Service. Spring offers a JAX-RPC factory which produces a proxy for Web Services.
  3. Make JMS Services Available to the Application at Runtime.
  4. Configure JMX: Expose the WebLogic Server Runtime MBean Server Connection to Spring.
  5. Configure Spring JDBC to Communicate With the Connection Pool.
  6. Use the Spring Transaction Abstraction Layer for Transaction Management.
  7. Make Use of WebLogic Server Clustering and Clustered Spring Remoting.

The following sections describe the details of redesigning a J2EE-based application to a Spring-based application. Where appropriate, these sections include sample code. In most cases the sample code is from MedRec-Spring.

Configure Spring Inversion of Control

In Spring, references to other beans (injected properties) are configured via a Spring configuration XML file, applicationContext-web.xml.

In MedRec-Spring, BEA replaced stateless session EJBs with POJOs in the Spring configuration file src\medrecEar\web\WEB-INF\applicationContext-web.xml as follows:

<bean name="/patient/record"


<property name="medRecClientServiceFacade">

<ref bean="medRecClientServiceFacade"/>



Then, in the application code, BEA defined setter methods for the corresponding bean. For example:

protected MedRecClientServiceFacade medRecClientServiceFacade;
  public void setMedRecClientServiceFacade(
      MedRecClientServiceFacade pMedRecClientServiceFacade){
    this.medRecClientServiceFacade = pMedRecClientServiceFacade;

Enable the Spring Web Services Client Service

To use Spring’s JAX-RPC factory which produces a proxy for Web Services, you configure the Spring JaxRpcPortProxyFactoryBean by implementing code such as the following; in MedRec-Spring, BEA implemented this code in the Spring configuration file src\physicianEar\APP-INF\classes\applicationContext-phys-service.xml.

<!-- reliable asynchronous web service for sending new medical records to medrec -->
<bean id="reliableClientWebServicesPortType"
<property name="wsdlDocumentUrl" value="http://${WS_HOST}:${WS_PORT}/ws_phys/PhysicianWebServices?WSDL"/>
<property name="portName" value="PhysicianWebServicesPort"/>
<property name="jaxRpcService">
<ref bean="generatedReliableService"/>
<property name="serviceInterface" value="com.bea.physician.webservices.client.PhysicianWebServicesPortType"/>
<property name="username" value="medrec_webservice_user"/>
<property name="password" value="weblogic"/>
<property name="customProperties">
<prop key="weblogic.wsee.complex">true</prop>
<> <!-- allows the jaxRpcService class to execute its constructor which loads in type mappings -->
<bean id="generatedReliableService" class="com.bea.physician.webservices.client.PhysicianWebServices_Impl">

In this code example, note that:

Make JMS Services Available to the Application at Runtime

In Spring, you must configure JMS services so that they are provided to the application during runtime. You can do this via a Spring Bean that represents a messaging destination. In MedRec-Spring, BEA made JMS services available to the application at runtime by implementing the following code in the Spring configuration file src\medrecEar\APP-INF\classes\applicationContext-jms.xml.

<bean id="uploadQueue" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName"
  <bean id="jmsConnFactory"
    <property name="jndiName"
  <bean id="uploadJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory">
      <ref bean="jmsConnFactory"/>
    <property name="defaultDestination">
      <ref bean="uploadQueue"/>

Configure JMX: Expose the WebLogic Server Runtime MBean Server Connection to Spring

You can expose WebLogic Server’s MBean Server to Spring through Spring’s MBeanServerConnectionFactoryBean, which is a convenience factory that produces an MBeanServerConnection that is established and cached during application deployment and can later be operated on by referencing beans. The MBeanServerConnectionFactoryBean can be configured to return the WebLogic Server Runtime MBean Server, and to obtain a connection to the WebLogic Server Domain Runtime MBean Server and the WebLogic Server Edit MBean Server.

Note: Because the WebLogic Server Domain Runtime MBean Server is not active during deployment, you must configure the MBeanServerConnectionFactoryBean to use Spring’s lazy instantiation. Lazy instantiation fetches the Spring Bean when it is invoked.

Exposing the WebLogic Server Runtime MBean Server Connection to Spring is demonstrated in the following code example, which, in MedRec-Spring, BEA implemented in the Spring configuration file medrecEar/APP-INF/classes/applicationContext-jmx.xml.

<> <!-- expose weblogic server's runtime mbeanserver connection -->
<bean id="runtimeMbeanServerConnection" class="">
<property name="serviceUrl" value="service:jmx:t3://${WS_HOST}:${WS_PORT}/jndi/"/>
<property name="environment">
<prop key="">${WS_USERNAME}</prop>
<prop key="">${WS_USERNAME}</prop>
<prop key="jmx.remote.protocol.provider.pkgs"></prop>

Configure Spring JDBC to Communicate With the Connection Pool

In MedRec-Spring, BEA used a datasource that references a JDBC connection pool that is managed by WebLogic Server and also employed Spring’s JdbcDaoSupport class. For information on JdbcDaoSupport, see the Spring documentation.

For an example of the way in which BEA implemented JDBC, see the MedRec-Spring class


See also the following code examples, which, for MecRec-Spring, BEA implemented in the Spring configuration files src\medrecEar\APP-INF\classes\applicationContext-db.xml and src\medrecEar\APP-INF\classes\applicationContext-jdbc.xml, respectively.

applicationContext-db.xml code example:

  <!-- datasource pool -->
  <bean id="dataSource"
    <property name="jndiName" value="jdbc/MedRecGlobalDataSourceXA"/>

applicationContext-jdbc.xml code example:

  <bean id="patientDao"

Additionally, in MedRec-Spring, BEA replaced entity EJBs with POJOs and made use of Spring JDBC for persistence. For an example, see the MedRec-Spring class \src\medrecEar\core\com\bea\medrec\domain\

Use the Spring Transaction Abstraction Layer for Transaction Management

Spring supports distributed transactions through WebLogic Server’s JTA implementation. You can also configure the Spring transaction manager to delegate responsibility to the WebLogic Server JTA transaction manager. This is accomplished via Spring’s WebLogicJtaTransactionManager class. BEA used this approach with MedRec-Spring in order to exactly mirror transaction management in the original version of MedRec.

To use the Spring transaction abstraction layer for transaction management and delegate responsibility to the WebLogic Server JTA transaction manager, you implement code such as the following, which BEA implemented in the Spring configuration files src\medrecEar\APP-INF\classes\applicationContext-tx.xml and src\medrecEar\APP-INF\classes\applicationContext-service.xml, respectively.

applicationContext-tx.xml code example:

<!-- spring's transaction manager delegates to WebLogic Server's transaction manager -->
<bean id="transactionManager" class="org.springframework.transaction.jta.WebLogicJtaTransactionManager">
<property name="transactionManagerName"

applicationContext-service.xml code example:

<!-- base transaction proxy for which medrec spring beans inherit-->
< bean id="baseTransactionProxy"
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributes">
<prop key="activate*">PROPAGATION_REQUIRED</prop>
<prop key="create*">PROPAGATION_REQUIRED</prop>
<prop key="compose*">PROPAGATION_REQUIRED</prop>
<prop key="deny*">PROPAGATION_REQUIRED</prop>
<prop key="getRecord*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="getPatient*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="getLog*">PROPAGATION_NOT_SUPPORTED</prop>
<prop key="process*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="send*">PROPAGATION_REQUIRED</prop>
< /bean>
<!-- single point of service for all medrec clients -->
<bean id="medRecClientServiceFacade"
<property name="target">
<bean class="com.bea.medrec.service.MedRecClientServiceFacadeImpl">
<property name="adminService">
<ref bean="adminService"/>
<property name="patientService">
<ref bean="patientService"/>
<property name="recordService">
<ref bean="recordService"/>
<property name="recordXmlProcessorService">
<ref bean="recordXmlProcessorService"/>

The transactionAttributes you specify define the way in which Spring begins and ends transactions. Because MedRec-Spring delegates transaction management to WebLogic JTA, management tasks such as transaction suspension and rollback are handled as specified by WebLogic’s transaction manager.

For more information on WebLogicJtaTransactionManager, see “Implementing Transaction Suspension in Spring” at

Make Use of WebLogic Server Clustering

Spring applications can take advantage of WebLogic Server’s clustering features. Because most Spring applications are packaged as Web applications (.war files), you need do not need to do anything special in order to take advantage of WebLogic Server clusters; all you need to do is deploy your Spring application to the servers in a WebLogic Server cluster.

Clustered Spring Remoting

The certification of Spring 1.2.8 and 2.0 on WebLogic Server extends the Spring JndiRmiProxyFactoryBean and its associated service exporter so that it supports proxying with any J2EE RMI implementation. To use the extension to the JndiRmiProxyFactoryBean and its exporter:

  1. Configure client support by implementing code such as the following:
  2. <bean id="proProxy" class="org.springframework.remoting.rmi.JndiRmiProxyFactoryBean">
    <property name="jndiName" value="t3://${serverName}:${rmiPort}/order"/>
    <property name="jndiEnvironment">
    <prop key="java.naming.factory.url.pkgs">weblogic.jndi.factories</prop>
    <property name="serviceInterface" value="org.springframework.samples.jpetstore.domain.logic.OrderService"/>
  3. Configure the service exporter by implementing code such as the following:
  4. <bean id="order-pro" class="org.springframework.remoting.rmi.JndiRmiServiceExporter">
    <property name="service" ref="petStore"/>
    <property name="serviceInterface" value="org.springframework.samples.jpetstore.domain.logic.OrderService"/>
    <property name="jndiName" value="order"/>


Spring Extension to the WebLogic Administration Console

You can use a Spring extension to the WebLogic Server Administration Console to monitor and manage Spring Beans, attributes, and operations that are defined in your application.

Installing the Spring Extension to the WebLogic Administration Console

To install the Spring extension to the WebLogic Administration Console, perform the following steps:

  1. Copy the spring-ext-server.jar file to your yourdomain/console-ext directory.
  2. Copy the spring-ext-client.jar file to your application’s WEB-INF/lib directory.
  3. Restart WebLogic Server.

Exposing Spring Beans Through the WebLogic Administration Console

In order to be able to access Spring Beans that are not MBeans through the WebLogic Administration Console, you must configure an MBeanExporter in the applicationContext.xml file and specify which beans to expose via the assembler. Make sure that the applicationName property is the deployed name of your application.


Support for Spring on WebLogic Server

For information on how BEA supports this release of WebLogic Server and the Spring Framework from Interface21, see Supported Configurations for Products with Spring Framework.

  Back to Top       Previous  Next