spring事务详细注释
<?xml version="1.0" encoding="UTF-8"?>
<context:component-scan base-package=“com.qfedu.service”></context:component-scan>
<!-- 2 创建Mybatis 的工厂对象 new SqlSessionFactory-->
<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<!--设置数据库连接池 -->
<property name="dataSource" ref="da"></property>
<!-- 加载mybatis主配置文件 classpath 表示classes目录所在路径 -->
<property name="configLocation" value="classpath:mybatis.xml"/>
<!-- 加载映射文件 -->
<property name="mapperLocations" value="classpath:com/qfedu/mapper/*.xml"/>
</bean>
<!--3设置Mybatis的映射接口 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
<!-- 设置映射接口所在包 -->
<property name="basePackage" value="com.qfedu.dao"></property>
</bean>
<!-- 1配置事务管理类 -->
<bean id="txManage" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="da"></property>
</bean>
<!-- 2配置事务的增强 -->
<tx:advice id="txAdvice" transaction-manager="txManage">
<tx:attributes>
<!-- 针对使用事务的add开头的方法
read-only 是否只读,true 是,false 可读可写
如果有插入等操作,设为为true,运行程序会报异常-->
<tx:method name="add*" read-only="false" propagation="REQUIRED"/>
<tx:method name="delete*" read-only="false" propagation="REQUIRES_NEW"/>
<tx:method name="update*" read-only="false" propagation="REQUIRED"/>
<tx:method name="find*" read-only="true" propagation="SUPPORTS"></tx:method>
<tx:method name="*" propagation="NOT_SUPPORTED"></tx:method>
</tx:attributes>
</tx:advice>
<!-- 3AOP配置 -->
<aop:config>
<aop:pointcut expression="execution(* com.qfedu.service.impl.*.*(..))" id="pc"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="pc"/>
</aop:config>