Spring管理iBatis事務
阿新 • • 發佈:2019-02-03
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd " ><!-- DataSource --><bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"><property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property><!--<property name="defaultAutoCommit" value="false"/>--><property name="url"> <value>jdbc:mysql://localhost/test</value></property><property name="username"><value>root</value></property><property name="password"><value>mysql</value></property></bean><!-- Spring iBatis Template --><bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"><property name="configLocation" value="SqlMapConfig.xml"/><property name="dataSource" ref="dataSource"/></bean><bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource"><ref local="dataSource"/></property></bean><bean id="userDAO" class="com.angi.ibatis.dao.UserDaoImpl"><property name="sqlMapClient"><ref bean="sqlMapClient"/></property></bean><bean id="userService" class="com.angi.ibatis.service.UserService"><property name="userDao"><ref bean="userDAO"/></property></bean><bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"><property name="beanNames"><list><value>userService</value></list></property><property name="interceptorNames"><list><value>transactionInterceptor</value></list></property></bean><bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor"><property name="transactionManager" ref="transactionManager"/><property name="transactionAttributes"><props><!-- 這裡的方法簽名可以精確到方法, 先懶惰一下全配置上 --><prop key="*">PROPAGATION_REQUIRED</prop></props></property></bean></beans>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd "
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource"><ref local="dataSource"/></property></bean><bean id="userDAO" class="com.angi.ibatis.dao.UserDaoImpl"><property name="sqlMapClient"><ref bean="sqlMapClient"/></property></bean><bean id="userService" class="com.angi.ibatis.service.UserService"><property name="userDao"><ref bean="userDAO"/></property></bean><bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"><property name="beanNames"><list><value>userService</value></list></property><property name="interceptorNames"><list><value>transactionInterceptor</value></list></property></bean><bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor"><property name="transactionManager" ref="transactionManager"/><property name="transactionAttributes"><props><!-- 這裡的方法簽名可以精確到方法, 先懶惰一下全配置上 --><prop key="*">PROPAGATION_REQUIRED</prop></props></property></bean></beans>