美文网首页
SpringBoot集成事务

SpringBoot集成事务

作者: 磨陀货_ | 来源:发表于2019-10-22 16:30 被阅读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主配置类加注解


...
@ImportResource("classpath:applicationContext-service.xml")
public class ApplicationConfig

3.方式二:注解方式

3.1主配置类--这个不打标签也可行,但是建议打上

3.2在*ServiceImpl加注解

相关文章

网友评论

      本文标题:SpringBoot集成事务

      本文链接:https://www.haomeiwen.com/subject/groqvctx.html