Annotation Type EnableTransactionManagement
http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/transaction/annotation/EnableTransactionManagement.html
Annotation Type EnableTransactionManagement
@Target(value=TYPE)
@Retention(value=RUNTIME)
@Documented
@Import(value=TransactionManagementConfigurationSelector.class)
public @interface EnableTransactionManagementEnables 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 whenJdbcFooRepository
'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 anyPlatformTransactionManager
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, theTransactionManagementConfigurer
callback interface may be implemented - notice theimplements
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, theannotationDrivenTransactionManager()
will be the one used for processing@Transactional
methods. SeeTransactionManagementConfigurer
Javadoc for further details.The
mode()
attribute controls how advice is applied; if the mode isAdviceMode.PROXY
(the default), then the other attributes control the behavior of the proxying.If the mode() is set to
AdviceMode.ASPECTJ
, then theproxyTargetClass()
attribute is obsolete. Note also that in this case thespring-aspects
module JAR must be present on the classpath.- Since:
- 3.1
- Author:
- Chris Beams
- See Also:
TransactionManagementConfigurer
,TransactionManagementConfigurationSelector
,ProxyTransactionManagementConfiguration
,AspectJTransactionManagementConfiguration
Annotation Type EnableTransactionManagement的更多相关文章
- Annotation Type @bean,@Import,@configuration使用--官方文档
@Target(value={METHOD,ANNOTATION_TYPE}) @Retention(value=RUNTIME) @Documented public @interface Bean ...
- 项目重新部署后报The attribute required is undefined for the annotation type XmlElementRef
在另外一台机器上部署项目,项目导进Eclipse中发现有异常 public class BooleanFeatureType extends FeatureBaseType{ @XmlElementR ...
- The attribute required is undefined for the annotation type XmlElementRef
异常描述: 几天没用的项目导进Eclipse中发现有异常 public class BooleanFeatureType extends FeatureBaseType{ @XmlElementRef ...
- junit的Test不能使用,报错信息:Test is not an annotation type
在使用junit的Test做测试时,注解@Test报错”Test is not an annotation type”,发现是因为测试类的类名命名为了Test,所以导致错误. 测试类类名不能直接命名为 ...
- Annotation Type ManyToMany->>>>>Oracle
Example 1: // In Customer class: @ManyToMany @JoinTable(name="CUST_PHONES") public Set< ...
- Java注解annotation : invalid type of annotation member
前言 首先,关于注解的介绍就不多描述了,网上有很多这方面的资料.本文主要是介绍如何处理标题中遇到的问题:invalid type of annotation member ? 正文 Annotatio ...
- Java-API-Package:org.springframwork.transaction.annotation
ylbtech-Java-API-Package:org.springframwork.transaction.annotation 1.返回顶部 1. @NonNullApi @NonNullFie ...
- 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 ...
- ANNOTATION PROCESSING 101 by Hannes Dorfmann — 10 Jan 2015
原文地址:http://hannesdorfmann.com/annotation-processing/annotationprocessing101 In this blog entry I wo ...
随机推荐
- 【BZOJ5137】Standing Out from the Herd(后缀自动机)
[BZOJ5137]Standing Out from the Herd(后缀自动机) 题面 BZOJ 洛谷 题解 构建广义后缀自动机 然后对于每个节点处理一下它的集合就好了 不知道为什么,我如果按照 ...
- loj2048 「HNOI2016」最小公倍数
link 题意: 给定一张$N$个顶点$M$条边的无向图(顶点编号为$1,2,...,n$),每条边上带有权值.所有权值都可以分解成$2^a \cdot 3^b$的形式. 现在有$q$个询问,每次询问 ...
- android 项目上传SVN不需要上传的文件
bin,gen 不用提交 因为这两个文件夹是自动生成的.如果提交可能会产生编译异常..settings也是自动生成,也不用提交.
- NOI.AC NOIP模拟赛 第五场 游记
NOI.AC NOIP模拟赛 第五场 游记 count 题目大意: 长度为\(n+1(n\le10^5)\)的序列\(A\),其中的每个数都是不大于\(n\)的正整数,且\(n\)以内每个正整数至少出 ...
- C/C++的64为长整型数的表示
在C/C++中,64为整型一直是一种没有确定规范的数据类型.现今主流的编译器中,对64为整型的支持也是标准不一,形态各异.一般来说,64位整型的定义方式有long long和__int64两种(VC还 ...
- spring-boot 速成(4) 自定义配置
spring-boot 提供了很多默认的配置项,但是开发过程中,总会有一些业务自己的配置项,下面示例了,如何添加一个自定义的配置: 一.写一个自定义配置的类 package com.example.c ...
- 《Go学习笔记 . 雨痕》流程控制(if、switch、for range、goto、continue、break)
Go 精简(合并)了流控制语句,虽然某些时候不够便捷,但够用. if...else... 条件表达式值必须是布尔类型,可省略括号,且左花括号不能另起一行. func main() { x := 3 i ...
- 在 DELPHI 中 procedure 型变量与 method 型变量的区别
Procedure型变量: 在DELPHI中,函数.过程的地址可以赋给一个特殊类型的变量,变量可用如下方式声明: var p : procedure(num:integer); //过程 或: var ...
- [Asp.net mvc]国际化
摘要 在实际项目中,经常遇到,开发的项目要提供给不同的国家使用,如果根据国家来开发不同的站点,肯定是非常耗时又耗成本的.asp.net中,提供了一种比较方便的方式,可以使用资源文件的方式,使我们的站点 ...
- CAD二次开发起步
1 环境搭建(VS 2017 + CAD 2019) CAD版本一般要比VS版本晚两年以上,比如我现在使用VS2017,则CAD要用2019版,至于CAD2018能不能用没试验过,有兴趣的小伙伴可以试 ...