zoukankan      html  css  js  c++  java
  • Spring @EnableTransactionManagement

    @EnableTransactionManagement // 启注解事务管理,等同于xml配置方式的 <tx:annotation-driven />

    关于事务管理器,不管是JPA还是JDBC等都实现自接口 PlatformTransactionManager.

    如果你添加的是 spring-boot-starter-jdbc 依赖,框架会默认注入 DataSourceTransactionManager 实例。

    如果你添加的是 spring-boot-starter-data-jpa 依赖,框架会默认注入 JpaTransactionManager 实例。

    @Configuration
    /*
    将MyBatisConfig类和JdbcConfig类交给Spring管理
     */
    @Import({MyBatisConfig.class,JdbcConfig.class})
    /**
     *等同于<context:component-scan base-package="com.itheima.service">
     */
    @ComponentScan( "com.itheima.service")
    /*开启事务管理
    等同于<tx:annotation-driven transaction-manager="transactionManager"/>
     */
    @EnableTransactionManagement
    public class SpringConfig {
        /*
        等同于<bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
         */
        @Bean("transactionManager")
        public DataSourceTransactionManager getDataSourceTxManager(@Autowired DataSource dataSource){
            DataSourceTransactionManager dtm = new DataSourceTransactionManager();
            //等同于<property name="dataSource" ref="dataSource"/>
            dtm.setDataSource(dataSource);
            return dtm;
        }
    }

     在使用Spring MVC的时候,配置文件中我们经常看到 annotation-driven 这样的注解,其含义就是支持注解,一般根据前缀 tx、mvc 等也能很直白的理解出来分别的作用。

    <tx:annotation-driven/> 就是支持事务注解的(@Transactional) 、<mvc:annotation-driven> 就是支持 MVC 注解的,说白了就是使Controller中可以使用MVC的各种注解。

    REF

    https://www.cnblogs.com/zhuyeshen/p/10907632.html

  • 相关阅读:
    MFC生成的exe程序不能在其他电脑上运行怎么办
    MFC开发软件支持多语言且同时支持xp和win7操作系统
    MFC创建模态对话框与非模态对话框
    如何定位BAD_ACCESS
    iOS中几种数据持久化方案
    iOS NSString相关问题
    SPU
    WIKI
    Mac怎么快速创建便签和发送附件的邮件
    利用你的Mission Control--设置快速回到桌面等操作
  • 原文地址:https://www.cnblogs.com/emanlee/p/15742620.html
Copyright © 2011-2022 走看看