数据源:
<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>
事务管理者:
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
被管理的对象:
<bean id="myBusinessObjectTarget" class="mybusiness.MyBusinessObject"></bean>
事务性代理对象:
<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>
说明:-MyCheckedException表示抛出此导常时回滚,+MyCheckedException表示抛出此导常时提交。
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
}
}
声明式事务的其中一种形式。^_^
posted on 2007-08-20 11:39
流浪汗 阅读(575)
评论(0) 编辑 收藏 所属分类:
Spring