<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/study"></property>
<property name="username" value="root"></property>
<property name="password" value=""></property>
</bean>
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/study"></property>
<property name="username" value="root"></property>
<property name="password" value=""></property>
</bean>
事務(wù)管理者:
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<property name="dataSource" ref="dataSource"></property>
</bean>
被管理的對(duì)象:

事務(wù)性代理對(duì)象:
<bean id="myBusinessObject" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"></property>
<property name="target" ref="myBusinessObjectTarget"></property>
<property name="transactionAttributes">
<props>
<prop key="myBusinessMethod">
PROPAGATION_REQUIRED,-MyCheckedException
</prop>
</props>
</property>
</bean>
說(shuō)明:-MyCheckedException表示拋出此導(dǎo)常時(shí)回滾,+MyCheckedException表示拋出此導(dǎo)常時(shí)提交。<property name="transactionManager" ref="transactionManager"></property>
<property name="target" ref="myBusinessObjectTarget"></property>
<property name="transactionAttributes">
<props>
<prop key="myBusinessMethod">
PROPAGATION_REQUIRED,-MyCheckedException
</prop>
</props>
</property>
</bean>
MyBusinessObject:
package mybusiness;
/**
*
* 2007-8-20 上午11:26:28
* @author chenlb
*/
public class MyBusinessObject {
public void myBusinessMethod() throws MyCheckedException {
// do some resource access
// return some result object or throw MycheckedException
}
}
/**
*
* 2007-8-20 上午11:26:28
* @author chenlb
*/
public class MyBusinessObject {
public void myBusinessMethod() throws MyCheckedException {
// do some resource access
// return some result object or throw MycheckedException
}
}
聲明式事務(wù)的其中一種形式。^_^