|
<?xmlversion="1.0"encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--
配置内置连接池 -->
<beanid="dataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<propertyname="driverClassName"value="com.mysql.jdbc.Driver"/>
<!--
jdbc:mysql:///tx_db
是 jdbc:mysql://localhost:3306/tx_db
的简写
-->
<propertyname="url"value="jdbc:mysql:///tx_db"/>
<propertyname="username"value="root"/>
<propertyname="password"value="8888"/>
</bean>
<!--
配置事务管理器 -->
<beanid="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!--
在 DataSourceTransactionManager
源代码中有
属性 dataSource
和其 set
方法,所以可以注入
-->
<propertyname="dataSource"ref="dataSource"/>
</bean>
<!--
配置事务的通知(增强) -->
<tx:adviceid="txAdvice"transaction-manager="transactionManager">
<tx:attributes>
<!--
isolation="DEFAULT"
隔离级别
propagation="REQUIRED"
传播行为
read-only="false"
只读
timeout="-1"
过期时间
rollback-for="" -Exception
no-rollback-for="" +Exception
-->
<!--
对进行事务操作的方法(一般是业务层方法)设置匹配规则,
如:transfer*
即所有以
transfer 开头的方法
-->
<tx:methodname="transfer"propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<!--
配置 AOP -->
<aop:config>
<!--
配置切入点 -->
<aop:pointcutexpression="execution(*
com.siwuxie095.service.AccountService.transfer(..))"id="pt"/>
<!--
配置切面(增强 +
切入点) -->
<aop:advisoradvice-ref="txAdvice"pointcut-ref="pt"/>
</aop:config>
<!--
配置对象并注入属性 -->
<beanid="accountService"class="com.siwuxie095.service.AccountService">
<propertyname="accountDao"ref="accountDao"></property>
</bean>
<beanid="accountDao"class="com.siwuxie095.dao.AccountDao">
<propertyname="jdbcTemplate"ref="jdbcTemplate"></property>
</bean>
<beanid="jdbcTemplate"class="org.springframework.jdbc.core.JdbcTemplate">
<!--
在 JdbcTemplate
源代码中有属性 dataSource
和其 set
方法,所以可以注入
-->
<propertyname="dataSource"ref="dataSource"></property>
</bean>
</beans>
|