http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/transaction/annotation/EnableTransactionManagement.html

org.springframework.transaction.annotation

Annotation Type EnableTransactionManagement


  • @Target(value=TYPE)
    @Retention(value=RUNTIME)
    @Documented
    @Import(value=TransactionManagementConfigurationSelector.class)
    public @interface EnableTransactionManagement
    Enables Spring's annotation-driven transaction management capability, similar to the support found in Spring's <tx:*> XML namespace. To be used on @Configuration classes as follows:

     @Configuration
    @EnableTransactionManagement
    public class AppConfig { @Bean
    public FooRepository fooRepository() {
    // configure and return a class having @Transactional methods
    return new JdbcFooRepository(dataSource());
    } @Bean
    public DataSource dataSource() {
    // configure and return the necessary JDBC DataSource
    } @Bean
    public PlatformTransactionManager txManager() {
    return new DataSourceTransactionManager(dataSource());
    }
    }

    For reference, the example above can be compared to the following Spring XML configuration:

     <beans>
    
         <tx:annotation-driven/>
    
         <bean id="fooRepository" class="com.foo.JdbcFooRepository">
    <constructor-arg ref="dataSource"/>
    </bean> <bean id="dataSource" class="com.vendor.VendorDataSource"/> <bean id="transactionManager" class="org.sfwk...DataSourceTransactionManager">
    <constructor-arg ref="dataSource"/>
    </bean> </beans>

    In both of the scenarios above, @EnableTransactionManagement and <tx:annotation-driven/> are responsible for registering the necessary Spring components that power annotation-driven transaction management, such as the TransactionInterceptor and the proxy- or AspectJ-based advice that weave the interceptor into the call stack when JdbcFooRepository's @Transactional methods are invoked.

    A minor difference between the two examples lies in the naming of the PlatformTransactionManager bean: In the @Bean case, the name is "txManager" (per the name of the method); in the XML case, the name is"transactionManager". The <tx:annotation-driven/> is hard-wired to look for a bean named "transactionManager" by default, however @EnableTransactionManagement is more flexible; it will fall back to a by-type lookup for any PlatformTransactionManager bean in the container. Thus the name can be "txManager", "transactionManager", or "tm": it simply does not matter.

    For those that wish to establish a more direct relationship between @EnableTransactionManagement and the exact transaction manager bean to be used, the TransactionManagementConfigurer callback interface may be implemented - notice the implements clause and the @Override-annotated method below:

     @Configuration
    @EnableTransactionManagement
    public class AppConfig implements TransactionManagementConfigurer { @Bean
    public FooRepository fooRepository() {
    // configure and return a class having @Transactional methods
    return new JdbcFooRepository(dataSource());
    } @Bean
    public DataSource dataSource() {
    // configure and return the necessary JDBC DataSource
    } @Bean
    public PlatformTransactionManager txManager() {
    return new DataSourceTransactionManager(dataSource());
    } @Override
    public PlatformTransactionManager annotationDrivenTransactionManager() {
    return txManager();
    }
    }

    This approach may be desirable simply because it is more explicit, or it may be necessary in order to distinguish between two PlatformTransactionManager beans present in the same container. As the name suggests, the annotationDrivenTransactionManager() will be the one used for processing @Transactional methods. See TransactionManagementConfigurer Javadoc for further details.

    The mode() attribute controls how advice is applied; if the mode is AdviceMode.PROXY (the default), then the other attributes control the behavior of the proxying.

    If the mode() is set to AdviceMode.ASPECTJ, then the proxyTargetClass() attribute is obsolete. Note also that in this case the spring-aspects module JAR must be present on the classpath.

    Since:
    3.1
    Author:
    Chris Beams
    See Also:
    TransactionManagementConfigurerTransactionManagementConfigurationSelectorProxyTransactionManagementConfigurationAspectJTransactionManagementConfiguration

Annotation Type EnableTransactionManagement的更多相关文章

  1. Annotation Type @bean,@Import,@configuration使用--官方文档

    @Target(value={METHOD,ANNOTATION_TYPE}) @Retention(value=RUNTIME) @Documented public @interface Bean ...

  2. 项目重新部署后报The attribute required is undefined for the annotation type XmlElementRef

    在另外一台机器上部署项目,项目导进Eclipse中发现有异常 public class BooleanFeatureType extends FeatureBaseType{ @XmlElementR ...

  3. The attribute required is undefined for the annotation type XmlElementRef

    异常描述: 几天没用的项目导进Eclipse中发现有异常 public class BooleanFeatureType extends FeatureBaseType{ @XmlElementRef ...

  4. junit的Test不能使用,报错信息:Test is not an annotation type

    在使用junit的Test做测试时,注解@Test报错”Test is not an annotation type”,发现是因为测试类的类名命名为了Test,所以导致错误. 测试类类名不能直接命名为 ...

  5. Annotation Type ManyToMany->>>>>Oracle

    Example 1: // In Customer class: @ManyToMany @JoinTable(name="CUST_PHONES") public Set< ...

  6. Java注解annotation : invalid type of annotation member

    前言 首先,关于注解的介绍就不多描述了,网上有很多这方面的资料.本文主要是介绍如何处理标题中遇到的问题:invalid type of annotation member ? 正文 Annotatio ...

  7. Java-API-Package:org.springframwork.transaction.annotation

    ylbtech-Java-API-Package:org.springframwork.transaction.annotation 1.返回顶部 1. @NonNullApi @NonNullFie ...

  8. The type javax.ws.rs.core.MediaType cannot be resolved. It is indirectly referenced from required .class files

    看到了http://stackoverflow.com/questions/5547162/eclipse-error-indirectly-referenced-from-required-clas ...

  9. ANNOTATION PROCESSING 101 by Hannes Dorfmann — 10 Jan 2015

    原文地址:http://hannesdorfmann.com/annotation-processing/annotationprocessing101 In this blog entry I wo ...

随机推荐

  1. Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem F. Turning Grille 暴力

    Problem F. Turning Grille 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c70 ...

  2. nginx优化(转)

    Puppet利用Nginx多端口实现负载均衡 对 Nginx SSL 的性能进行调整 一.nginx 配置文件中基本设置: 1.  worker_processes 8; 2.  worker_cpu ...

  3. Who is YaoGe.(搞笑篇)

      耀哥是google的大牛.主持google各种牛逼分布式系统的设计,比方Mapreduce之类的,关于大神的传说,如同春哥一样多,当然,有些传说仅仅有程序猿能明确! 耀哥当初面试Google时.被 ...

  4. Go 导入当前项目下的包

    其实和其他语言很类似 import (     "../controllers" //这里就是导入上一级目录中的controllers     "./models&quo ...

  5. 荣耀 6 安装 SD 卡,提示:SD卡已安全移除

    先前买了个 荣耀6(购买链接),自带存储只有 16G,用来一段时间后,老是提示存储不足.后来发现是 微信 等软件占用了好多存储(缓存),, 好吧,在京东上买了个 64G 扩展卡(购买链接),安装过程如 ...

  6. Programming 2D Games 读书笔记(第五章)

      http://www.programming2dgames.com/chapter5.htm 示例一:Planet 真正示例的开始,首先是载入2张图片 1.Graphics添加了2个方法 load ...

  7. Html学习笔记3

    1表格的标题和表头: <table> <caption>成绩单</caption> <tr> <th>姓名</th> <t ...

  8. 基于设备树的controller学习(2)

    作者 彭东林 pengdonglin137@163.com 平台 TQ2440 Linux-4.10.17 概述 上一篇大概介绍了一下demo-controller的结构,下面结合驱动分析.   正文 ...

  9. 基于设备树的TQ2440的中断(1)

    作者 姓名:彭东林 E-mail:pengdonglin137@163.com QQ:405728433 平台 板子:TQ2440 内核:Linux-4.9 u-boot: 2015.04 工具链: ...

  10. 委托、Lambda表达式、事件系列07,使用EventHandler委托

    谈到事件注册,EventHandler是最常用的. EventHandler是一个委托,接收2个形参.sender是指事件的发起者,e代表事件参数. □ 使用EventHandler实现猜拳游戏 使用 ...