数据源:
事务管理者:
被管理的对象:
<
bean
id
="myBusinessObjectTarget"
class
="mybusiness.MyBusinessObject"
></
bean
>
事务性代理对象:
MyBusinessObject:
声明式事务的其中一种形式。^_^
<
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 >
事务管理者:
<
bean
id
="transactionManager"
class
="org.springframework.jdbc.datasource.DataSourceTransactionManager"
>
< property name ="dataSource" ref ="dataSource" ></ property >
</ bean >
< property name ="dataSource" ref ="dataSource" ></ property >
</ bean >
被管理的对象:
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
事务性代理对象:
<
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表示抛出此导常时提交。
< 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
}
}
声明式事务的其中一种形式。^_^