Developing Applications with WebLogic Server
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
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.
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 Integration with WebLogic Server" at http://dev2dev.bea.com/pub/a/2005/09/spring_integration_weblogic_server.html.
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 9.0, and the Spring Framework. For information on WebLogic Server 9.0, see BEA WebLogic Server 9.0 Documentation. For information on the Spring Framework, see http://www.springframework.org/.
To transform a J2EE-based application to a Spring-based application, you perform the following steps as desired:
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.
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:
class="com.bea.medrec.web.patient.actions.ViewRecordAction">
<property name="medRecClientServiceFacade">
<ref bean="medRecClientServiceFacade"/>
</bean>
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;
}
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"
class="org.springframework.remoting.jaxrpc.JaxRpcPortProxyFactoryBean"
lazy-init="true">
<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>
<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"><props>
<prop key="weblogic.wsee.complex">true</prop>
</props>
</property>
</bean>
<> <!-- allows the jaxRpcService class to execute its constructor which loads in type mappings -->
<bean id="generatedReliableService" class="com.bea.physician.webservices.client.PhysicianWebServices_Impl">
</bean>
In this code example, note that:
serviceInterface
represents Web Services operations.customProperties
property allows for custom WebLogic Server Web Service stub properties.jaxRpcService
value is set to WebLogic Server's generated JAX-RPC implementation service.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 Med-Rec 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"
value="com.bea.medrec.messagging.MedicalRecordUploadQueue"/>
</bean>
<bean id="jmsConnFactory"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName"
value="com.bea.medrec.messagging.MedRecQueueConnectionFactory"/>
</bean>
<bean id="uploadJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory">
<ref bean="jmsConnFactory"/>
</property>
<property name="defaultDestination">
<ref bean="uploadQueue"/>
</property>
</bean>
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="org.springframework.jmx.support.MBeanServerConnectionFactoryBean">
<property name="serviceUrl" value="service:jmx:t3://${WS_HOST}:${WS_PORT}/jndi/weblogic.management.mbeanservers.runtime"/>
<property name="environment">
<props>
<prop key="java.naming.security.principal">${WS_USERNAME}</prop>
<prop key="java.naming.security.credentials">${WS_USERNAME}</prop>
<prop key="jmx.remote.protocol.provider.pkgs">weblogic.management.remote</prop>
</props>
</property>
</bean>
In MedRec-Spring, BEA used a data source 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
src\medrecEar\dao\com\bea\medrec\dao\jdbc\JdbcPatientDao.java
See also the following code examples, which, for MedRec-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"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/MedRecGlobalDataSourceXA"/>
</bean>
applicationContext-jdbc.xml
code example:
<bean id="patientDao"
class="com.bea.medrec.dao.jdbc.JdbcPointBasePatientDao"
autowire="byType"/>
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\Address.java
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"
value="javax.transaction.TransactionManager"/>
</bean>
applicationContext-service.xml
code example:
<!-- base transaction proxy for which medrec spring beans inherit-->
< bean id="baseTransactionProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributes">
<props>
<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>
</props>
</property>
< /bean>
<!-- single point of service for all medrec clients -->
<bean id="medRecClientServiceFacade"
parent="baseTransactionProxy">
<property name="target">
<bean class="com.bea.medrec.service.MedRecClientServiceFacadeImpl">
<property name="adminService">
<ref bean="adminService"/>
</property>
<property name="patientService">
<ref bean="patientService"/>
</property>
<property name="recordService">
<ref bean="recordService"/>
</property>
<property name="recordXmlProcessorService">
<ref bean="recordXmlProcessorService"/>
</property>
</bean>
</property>
</bean>
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 http://dev2dev.bea.com/pub/a/2005/07/spring_transactions.html.
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.
The certification of Spring 1.2.5 on WebLogic Server 9.0 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:
<bean id="proProxy" class="org.springframework.remoting.rmi.JndiRmiProxyFactoryBean">
<property name="jndiName" value="t3://${serverName}:${rmiPort}/order"/>
</property>
<property name="jndiEnvironment">
<props>
<prop key="java.naming.factory.url.pkgs">weblogic.jndi.factories</prop>
</props>
</property>
<property name="serviceInterface" value="org.springframework.samples.jpetstore.domain.logic.OrderService"/>
</bean>
<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"/>
</bean>
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.
To install the Spring extension to the WebLogic Administration Console, perform the following steps:
In order to be able to access Spring Beans that are not MBeans through the Web Logic 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.
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.
![]() |
![]() |
![]() |