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. [AHOI2013]作业

    [AHOI2013]作业 题目大意: 给定一个长度为\(n(n\le10^5)\)的数列\(A(1\le A_i\le n)\).\(m(m\le10^6)\)次询问,每次询问区间\([l,r]\)内 ...

  2. C# 高级编程9 介绍篇

    对等网络 在日常软件环境中,解决了以下问题: 不断增加的客户端通讯负载放在服务器上,服务器必须与每个客户端进行通讯,导致站点崩溃.大流量消耗.服务器无法响应等问题. 因此产生了P2B网络技术. 使用P ...

  3. Slickflow.NET 开源工作流引擎高级开发(四) -- 硬核编码:代码式快速构建流程图

    前言:通过设计器交互来创建流程图是比较常见的方式,这种方式是比较方便业务人员对流程的操作.然而,在需要流程模板,或者技术开发阶段以及一些自动化流程的处理过程中,使用代码快速创建流程图也是一种非常有必要 ...

  4. Graph database_neo4j 底层存储结构分析(1)

    1       neo4j 中节点和关系的物理存储模型 1.1  neo4j存储模型 The node records contain only a pointer to their first pr ...

  5. 使用 IntraWeb (25) - 基本控件之 TIWRegion

    这应该是 IW 中最重要的容器了, 和它同父的还有 TIWTabControl TIWRegion 所在单元及继承链: IWRegion.TIWRegion 主要成员: property Align: ...

  6. 微信小程序开发需要注意的29个坑

    1.小程序名称可以由中文.数字.英文.长度在3-20个字符之间,一个中文字等于2个字符. 2.小程序名称不得与公众平台已有的订阅号.服务号重复.如提示重名,请更换名称进行设置. 3.小程序名称在帐号信 ...

  7. STM32输入捕获模式设置并用DMA接收数据

    参考: STM32的PWM输入模式设置并用DMA接收数据 Input capture mode The input stage samples the corresponding TIx input ...

  8. MSDN WinUSB Example

    The WinUSB user-mode library uses device interface classes to communicate with the kernel-mode USB s ...

  9. 《Go学习笔记 . 雨痕》方法

    一.定义 方法 是与对象实例绑定的特殊函数. 方法 是面向对象编程的基本概念,用于维护和展示对象的自身状态.对象是内敛的,每个实例都有各自不同的独立特征,以 属性 和 方法 来暴露对外通信接口.普通函 ...

  10. 什么是.Net, IL, CLI, BCL, FCL, CTS, CLS, CLR, JIT

    什么是.NET? 起源:比尔盖茨在2000年的Professional Developers Conference介绍了一个崭新的平台叫作Next Generation Windows Service ...