developing applications using WebLogic Server
Spring Application Reference
The following sections describe the Spring Framework based applications that develop and manage WebLogic Server. In most cases, the information in these sections is introduced from the perspective of creating medrec-spring. About Spring on the WebLogic Server to redesign the Java-based application to a spring-based application to the spring extension of the WebLogic management console
about Spring on the WebLogic Server
To demonstrate how Spring leverages the WebLogic Server Enterprise feature, BEA redesigned the Avitek medical records sample application (MEDREC), replacing the core Java EE component with the spring component. For additional information about the MEDREC architecture and its redesign, see the article located under Http://dev2dev.bea.com/pub/a/2005/09/spring_integration_weblogic_server.html. Spring integration with WebLogic Server ".
The following sections describe the key steps that BEA performs when redesigning Medrec. You can use this information if you want to redesign your own Java-based WebLogic Server application using the Spring component. You can also take advantage of this information if you want to create a new Spring component based application for WebLogic Server.
Let's assume you're familiar with the Java EE concept, WebLogic Server, and Spring Framework. For information about WebLogic server, see the BEA WebLogic Server 9.2 documentation. For information about spring on the BEA dev2dev Web site, see Spring Resource Page. For general information about the Spring Framework, see http://www.springframework.org/.
redesign a Java-based application into a Spring-based application
To convert an application based on Java EE to a spring based application, you need to perform the steps described below: Configure Spring control inversion (inversion of controls). Enable the Spring WEB Service client service. Spring provides a JAX-RPC factory for Web Service generation agents. Make the JMS service available to run-time applications. Configure JMX: Exposes the WebLogic server Runtime MBean Server connection to Spring. Configure Spring JDBC to communicate with the connection buffer pool. Use the spring transaction abstraction layer for transaction management using the WebLogic Server cluster and the cluster spring Remoting.
The following sections describe the details of redesigning a Java-based application into a Spring-based application. These sections contain sample code in the appropriate place. In most cases, the sample code comes from medrec-spring. Configure Spring control inversion (inversion of controls)
In spring, references to other beans (injection properties) are configured through the spring configuration XML file Applicationcontext-web.xml.
In Medrec-spring, BEA uses POJO instead of a stateless session EJB in the Spring configuration file Src/medrecear/web/web-inf/applicationcontext-web.xml, as follows:
<bean name= "/patient/record"
class= "Com.bea.medrec.web.patient.actions.ViewRecordAction" >
<property name= "Medrecclientservicefacade" >
<ref bean= "Medrecclientservicefacade"/>
</property>
</bean>
Then, in the application code, BEA defines the installer method for the appropriate Bean. For example:
protected Medrecclientservicefacade Medrecclientservicefacade;
public void Setmedrecclientservicefacade (
Medrecclientservicefacade Pmedrecclientservicefacade) {
This.medrecclientservicefacade = Pmedrecclientservicefacade;
}
enable the Spring Web Service client Service
To use the spring Jax-RPC factory for the Web Service generation agent, you need to configure the spring Jaxrpcportproxyfactorybean by implementing the following code; in Medrec-spring, BEA is in Sprin This code is implemented in the G configuration file Src/physicianear/app-inf/classes/applicationcontext-phys-service.xml.
<!--to send new medical records to MEDREC reliable asynchronous Web Service;
<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 perform its constructor for loading type mappings-->
<bean id= "Generatedreliableservice" class= "Com.bea.physician.webservices.client.PhysicianWebServices_Impl" >
</bean>
In the code example, note that serviceinterface represents a Web Service operation. The CustomProperties property allows you to customize WebLogic Server Web Service stub control properties. The Jaxrpcservice value is set to the JAX-RPC implementation service generated by WebLogic Server. making the JMS service available to run-time applications
In Spring, you must configure the JMS service to provide them to the Run-time application. This can be done by means of a Spring Bean that represents the destination of the message delivery. In Med-rec Spring, BEA implements the following code in the Spring configuration file Src/medrecear/app-inf/classes/applicationcontext-jms.xml to make the JMS Services are available to run-time applications.
<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>
Configure JMX: Expose the WebLogic server Runtime MBean Server connection to Spring
You can expose the WebLogic server's MBean servers to spring by means of Spring's mbeanserverconnectionfactorybean, which is a build Mbeanserverconnection (This mbeanserverconnection is established and cached during application deployment and is later referenced by the Bean to be able to manipulate it). Mbeanserverconnectionfactorybean can be configured to return WebLogic server Runtime Mbean server and get to WebLogic server Domain Runtime Mbean S Connection to erver and WebLogic server Edit MBean server.
Attention: |
Because WebLogic server Domain Runtime MBean Server is not active at deployment, Mbeanserverconnectionfactorybean must be configured to use Spring's lazy Insta Ntiation. When Lazy instantiation is invoked, it extracts the Spring Bean. |
The following code example demonstrates the process of exposing the WebLogic server Runtime MBean Server connection to Spring, and in Medrec-spring, BEA in the Spring configuration file Medrecear/app-inf/cla Implement this procedure in Sses/applicationcontext-jmx.xml.
<> <!--expose the Run-time mbeanserver connection of WebLogic Server-->
<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>
Configure Spring JDBC to communicate with the connection buffer pool
In Medrec-spring, BEA uses a data source that references the JDBC connection buffer pool (this JDBC connection buffer pool is managed by WebLogic Server) and also uses the Jdbcdaosupport class. For information about Jdbcdaosupport, see the Spring documentation.
For an example of how BEA implements JDBC, see the Medrec-spring class
Src/medrecear/dao/com/bea/medrec/dao/jdbc/jdbcpatientdao.java
See also the following code example for Mecrec-spring,bea in the Spring configuration file Src/medrecear/app-inf/classes/applicationcontext-db.xml and src/respectively Implement the code in Medrecear/app-inf/classes/applicationcontext-jdbc.xml.
Applicationcontext-db.xml code Example:
<!--data source buffer 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"/>
In addition, in Medrec-spring, BEA replaces the entity EJB with POJO and uses the persistence of Spring JDBC. For an example, see Medrec-spring class/src/medrecear/core/com/bea/medrec/domain/address.java. transaction Management Using the Spring transaction abstraction Layer
Through the JTA implementation of WebLogic Server, Spring supports distributed transactions. You can also configure the Spring transaction manager to delegate responsibility to the WebLogic Server JTA transaction manager. This can be achieved through Spring's Weblogicjtatransactionmanager class. BEA uses this method in medrec-spring to correctly mimic the transaction management of the original version Medrec.
To use the spring transaction abstraction layer for transaction management and delegate responsibility to the WebLogic Server JTA transaction Manager, you must implement the code shown below, where BEA is in the spring configuration file src/medrecear/app-inf/classes/ Implement the code in Applicationcontext-tx.xml and Src/medrecear/app-inf/classes/applicationcontext-service.xml.
Applicationcontext-tx.xml code Example:
<!--Spring's transaction manager delegation to the WebLogic Server transaction manager-->
<bean id= "TransactionManager" class= "Org.springframework.transaction.jta.WebLogicJtaTransactionManager" >
<property name= "Transactionmanagername"
Value= "Javax.transaction.TransactionManager"/>
</bean>
Applicationcontext-service.xml code Example:
<!--the basic transaction Agent--> Medrec Spring Bean to 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 defines how Spring starts and ends transactions. Because medrec-spring delegate transaction management to WebLogic JTA, administrative tasks such as transaction suspension and rollback are handled as specified by the WebLogic transaction manager.
For more information about Weblogicjtatransactionmanager, see the "in Http://dev2dev.bea.com/pub/a/2005/07/spring_transactions.html" Implementing Transaction Suspension in Spring ". using the WebLogic Server cluster
The Spring application can use the cluster capabilities of the WebLogic Server. Because most Spring applications are packaged as WEB applications (. war files), to use the WebLogic server cluster, you do not need to do any special work, all you need to do is deploy the spring application to the WebLogic server cluster The service device. Cluster Spring Remoting
The certificate for Spring 1.2.8 on WebLogic Server extends the spring Jndirmiproxyfactorybean and its associated service exporter to enable it to implement a support agent using any Java-ee RMI. To use the extension for Jndirmiproxyfactorybean and its exporter, do the following: Configure client support by implementing the code shown below:
<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>
Configure the service exporter by implementing the code shown below:
<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>
Spring extensions to the WebLogic management console
You can use the spring extension for the WebLogic Server Management Console to monitor and manage the spring beans, attributes, and operations defined in your application. Install the Spring extension to the WebLogic management console
To install the Spring extension to the WebLogic management console, follow these steps: Copy the Spring-ext-server.jar file to the Yourdomain/console-ext directory. Copy the Spring-ext-client.jar file to the application's Web-inf/lib directory. Restart the WebLogic Server. exposing Spring beans through the WebLogic management console
In order to be able to access a Spring Bean that is not an MBean through the WebLogic management console, you must configure the Mbeanexporter in the Applicationcontext.xml file and specify which beans will be exposed through an assembler. Make sure the ApplicationName property is the deployment name of your application.
support Spring on the WebLogic Server
For information about how BEA supports this version of WebLogic Server and the Interface21 Spring Framework, see Supported Configurations for products with SPR ing Framework.