SpringBoot集成事务
2019-10-22 本文已影响0人
磨陀货_
1.导包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
2。方式一:手动
2.1配置事务.xml
<!-- 配置事物管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<aop:config>
<aop:pointcut expression="execution(* cn.itsource.web.controller.service..*.*(..))" id="coreServicePointcut"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="coreServicePointcut"/>
</aop:config>
<!-- aop应用事务管理 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="select*" read-only="true"/>
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
2.2主配置类加注解
![](https://img.haomeiwen.com/i17114228/69617d945b1a3610.png)
...
@ImportResource("classpath:applicationContext-service.xml")
public class ApplicationConfig
3.方式二:注解方式
3.1主配置类--这个不打标签也可行,但是建议打上
![](https://img.haomeiwen.com/i17114228/fd8e1de681e402d1.png)
3.2在*ServiceImpl加注解
![](https://img.haomeiwen.com/i17114228/0f39c2ec34045eb1.png)