浏览 3856 次
锁定老帖子 主题:spring代理iBATIS时事务不能回滚
该帖已经被评为新手帖
|
|
---|---|
作者 | 正文 |
发表时间:2008-06-17
kkkk如题! 废话不多说了,直接上配置,配置如下,各位看了便知! applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"><value>classpath:jdbc.properties</value></property> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="url"><value>${jdbc.url}</value></property> <property name="driverClassName"><value>${jdbc.driver}</value></property> <property name="username"><value>${jdbc.username}</value></property> <property name="password"><value>${jdbc.password}</value></property> <property name="defaultAutoCommit" value="false"></property> </bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor" > <property name="transactionManager" ref="transactionManager" /> <property name="transactionAttributes"> <props> <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="*">PROPAGATION_REQUIRED,-Exception</prop> </props> </property> </bean> <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="beanNames"> <value>*Service</value></property> <property name="interceptorNames"><value>transactionInterceptor</value></property> </bean> <bean id="sqlMapClientFactory" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <property name="configLocation"><value>classpath:sqlMapConfig.xml</value></property> <property name="dataSource" ref="dataSource"></property> <property name="lobHandler"> <bean class="org.springframework.jdbc.support.lob.DefaultLobHandler"/> </property> </bean> <bean id="sqlMapTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate"> <property name="sqlMapClient" ref="sqlMapClientFactory" /> <property name="exceptionTranslator"> <bean class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator"> <property name="dataSource" ref="dataSource" /> </bean> </property> </bean> </beans> daoContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="employeeDao" class="mypackage.dao.impl.EmployeeDaoImpl"> <property name="sqlMapTemplate"> <ref bean="sqlMapTemplate" /> </property> </bean> </beans> serviceContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="employeeService" class="mypackage.service.impl.EmployeeServiceImpl"> <property name="employeeDao"><ref bean="employeeDao" /></property> </bean> </beans> 在EmployeeServiceImpl中故意让程序抛出了exception,但是事务仍然提交了:-( 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2008-06-17
EmployeeDaoImpl.java package mypackage.dao.impl; import org.springframework.orm.ibatis.SqlMapClientTemplate; import mypackage.dao.EmployeeDao; import mypackage.pojo.Employee; public class EmployeeDaoImpl implements EmployeeDao { private SqlMapClientTemplate sqlMapTemplate; public void saveEmployee(Employee emp) { sqlMapTemplate.insert("employee.save" emp); } public void setSqlMapTemplate(SqlMapClientTemplate sqlMapTemplate) { this.sqlMapTemplate = sqlMapTemplate; } public SqlMapClientTemplate getSqlMapTemplate() { return sqlMapTemplate; } } EmployeeServiceImpl.java package mypackage.service.impl; import mypackage.dao.EmployeeDao; import mypackage.pojo.Employee; import mypackage.service.EmployeeService; public class EmployeeServiceImpl implements EmployeeService { private EmployeeDao dao; public void saveEmp(Employee emp) { dao.saveEmployee(emp); Integer.parseInt("回滚回滚回滚吧!!!"); } public void setEmployeeDao(EmployeeDao dao) { this.dao = dao; } } |
|
返回顶楼 | |
发表时间:2008-06-18
Where is ur pattern matching beanName(s) declared?
I can only find id declaration of those "*Service" beans... Regards. |
|
返回顶楼 | |
发表时间:2008-07-23
Spring代理需要一个RuntimeException才可以回滚。
|
|
返回顶楼 | |