User Manual

Declarative Transaction Management
This section describes the following steps to configure transactions in Spring applications using
declarative approach:
“Defining the Transactional Object” (page 67)
“Defining the Transactional Advice” (page 68)
“Defining the Transactional Execution Point” (page 68)
“Defining the Transaction Datasource” (page 69)
“Defining the PlatformTransactionManager” (page 69)
“Defining the Transaction Rollback (Optional)” (page 70)
NOTE: In a typical Spring application, this configuration must be done in the
applicationContext.xml file.
Defining the Transactional Object
To define a service object to be used as a transactional object, add the following line in the
applicationContext.xml file:
<bean id="<bean name>" class="<package name>.<service name>"/>
For example:
Consider the following service interface, and its implementation:
// the service interface that we want to make transactional
package a.b.service;
public interface MyService {
MyObject getMyObject(String myObjectName);
MyObject getMyObject(String myObjectName, String myObjectDesc);
void insertMyObject(MyObject myobject);
void updateMyObject(MyObject myobject);
}
// an implementation of the above interface
package a.b.service;
public class DefaultMyService implements MyService {
public MyObject getMyObject(String myObjectName) {
throw new UnsupportedOperationException();
}
public MyObject getMyObject(String myObjectName, String myObjectDesc) {
throw new UnsupportedOperationException();
}
public void insertMyObject(MyObject myobject) {
throw new UnsupportedOperationException();
}
public void updateMyObject(MyObject myobject) {
throw new UnsupportedOperationException();
}
To make the DefaultMyService service object as transactional, the configuration in the
applicationContext.xml file is:
<!-- this is the service object that we want to make transactional -->
<bean id="myService" class="a.b.service.DefaultMyService"/>
Spring Framework Configurations 67