<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/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!--配置业务层-->
<bean id="accountService" class="com.zsw.sevice.impl.AccountServiceImpl">
<property name="accountDao" ref="accountDao"></property>
</bean>
<bean class="com.zsw.dao.impl.AccountDaoImpl" id="accountDao">
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="dataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql:///spring"></property>
<property name="username" value="root"></property>
<property name="password" value="123123"></property>
</bean>
<!--spring 基于xml的声明式事务控制
1. 配置事务管理器
2. 配置事务通知
3.配置aop中的通用切入点表达式
4. 建立切入点表达式和事务通知的对应关系
5. 配置事务的属性 isolation="指定事务的隔离级别"
-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!--
propagation="指定事务的传播行为 REQUIRED表示一定会有事务 增删改的选择 查询方法可以选择SUPPORTS"
read-only ="事务是否只读 只有查询方法才能设置为true只读 默认值 false"
timeout = "用于指定事务的超时时间" 默认值为 -1 如果指定了数值以秒为单位
rollback-for="用于指定一个异常 当产生改异常时 事务回滚 产生其他异常时 事务不会滚 没有默认值 任何异常都回滚"
no-rollback-for=""用于指定一个异常 当产生改异常时 事务不回滚 产生其他异常时 事务会滚 没有默认值 任何异常都回滚"
-->
<tx:method name="*" propagation="REQUIRED" read-only="false"/>
<tx:method name="find*" read-only="true" propagation="SUPPORTS"></tx:method>
</tx:attributes>
</tx:advice>
<aop:config>
<!-- 配置切点表达式-->
<aop:pointcut id="pt1" expression=" execution(* com.zsw.sevice.impl.*.*(..))"></aop:pointcut>
<!--配置切入 点表达式和事务通知的对应关系-->
<aop:advisor advice-ref="txAdvice" pointcut-ref="pt1">
</aop:advisor>
</aop:config>
</beans>