57 lines
2.7 KiB
XML
57 lines
2.7 KiB
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"
|
|
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.xsd
|
|
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
|
|
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
|
|
">
|
|
|
|
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
|
|
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
|
|
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/spring_jdbc"/>
|
|
<property name="user" value="root"/>
|
|
<property name="password" value="root"/>
|
|
</bean>
|
|
|
|
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
|
|
<property name="dataSource" ref="dataSource"/>
|
|
</bean>
|
|
|
|
<bean id="accountDao" class="com.itheima.dao.impl.AccountDaoImpl">
|
|
<property name="jdbcTemplate" ref="jdbcTemplate"/>
|
|
</bean>
|
|
|
|
<!--目标对象,内部的方法就是切点-->
|
|
<bean id="accountService" class="com.itheima.service.impl.AccountServiceImpl">
|
|
<property name="accountDao" ref="accountDao"/>
|
|
</bean>
|
|
|
|
<!--配置一个平台事务管理器,不同的dao实现可能class也不同-->
|
|
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
|
<property name="dataSource" ref="dataSource"/>
|
|
</bean>
|
|
|
|
<!--通知 事务的增强-->
|
|
<tx:advice id="txAdvice" transaction-manager="transactionManager">
|
|
<!--设置事务的属性信息-->
|
|
<tx:attributes>
|
|
<!-- 对不同的方法进行事务控制-->
|
|
<tx:method name="transfer" isolation="DEFAULT" propagation="REQUIRED" timeout="-1" read-only="false"/>
|
|
<tx:method name="save" isolation="DEFAULT" propagation="REQUIRED" timeout="-1" read-only="false"/>
|
|
<tx:method name="findAll" isolation="DEFAULT" propagation="REQUIRED" timeout="-1" read-only="true"/>
|
|
<tx:method name="update*" isolation="DEFAULT" propagation="REQUIRED" timeout="-1" read-only="true"/>
|
|
<tx:method name="*"/>
|
|
</tx:attributes>
|
|
</tx:advice>
|
|
|
|
<!--配置事务的aop植入-->
|
|
<aop:config>
|
|
<aop:pointcut id="txPoint" expression="execution(* com.itheima.service.impl.*.*(..))"/>
|
|
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint"/>
|
|
</aop:config>
|
|
|
|
|
|
</beans> |