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@Configurationclasses 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,
@EnableTransactionManagementand<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@Transactionalmethods are invoked.A minor difference between the two examples lies in the naming of the
PlatformTransactionManagerbean: In the@Beancase, 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@EnableTransactionManagementis more flexible; it will fall back to a by-type lookup for anyPlatformTransactionManagerbean 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
@EnableTransactionManagementand the exact transaction manager bean to be used, theTransactionManagementConfigurercallback interface may be implemented - notice theimplementsclause 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
PlatformTransactionManagerbeans present in the same container. As the name suggests, theannotationDrivenTransactionManager()will be the one used for processing@Transactionalmethods. SeeTransactionManagementConfigurerJavadoc 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-aspectsmodule 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 ...
随机推荐
- Visual Studio新的 .csporj 文件
Visual Studio新的 .csporj 文件非常方便,虽然目前还不支持WPF.WinForm等工程,但应用到控制台程序,类库还是没有任何问题的.只需要简单的用如下内容替换老的csproj即可: ...
- 解决oracle语句中 含数字的字符串按数字排序问题
普通排序利用:order by 字段名 ASC 但是遇到有中文而且类型是varchar类型的结果就是这样 政采代(甲)字第0298号 政采代(甲)字第0421号 政采代(甲)字第1098号 政采代(甲 ...
- 【Go命令教程】7. go run
Go 源码文件包括:命令源码文件.库源码文件 和 测试源码文件.其中,命令源码文件 总应该属于 main 代码包,且在其中有无参数声明.无结果声明的 main 函数.单个命令源码文件可以被单独编译,也 ...
- GetKeyState(vk_control)
GetKeyState(vk_control) 返回负数 , 说明按键被按下了
- 自定义一个可以被序列化的泛型Dictionary<TKey,TValue>集合
Dictionary是一个键值类型的集合.它有点像数组,但Dictionary的键可以是任何类型,内部使用Hash Table存储键和值.本篇自定义一个类型安全的泛型Dictionary<TKe ...
- mysql time zone时区的错误解决
错误提示: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zon ...
- iOS越狱知多少?
著名iOS黑客团队Evad3rs上周上线了evasi0n 官网,用于展示他们破解iOS 6 和iOS 6.1 系统的进度.据官网显示,其越狱工具evasi0n已正式上线,支持iPhone.iPad等 ...
- 【Android病毒分析报告】- 手机支付毒王“银行悍匪”的前世今生
from://http://blog.csdn.net/androidsecurity/article/details/18984165 2014年1月8日,央视曝光了一款名为“银行悍匪”的手机银行木 ...
- Cocos2d-x开源、跨平台的游戏引擎
from://http://blog.linguofeng.com/pages/language/c/Cocos2dx.html Cocos2d-x 开源.跨平台的游戏引擎 一.下载 http://c ...
- Linux学习2-在阿里云服务器上部署禅道环境
前言 以前出去面试总会被问到:测试环境怎么搭建?刚工作1-2年不会搭建测试环境还可以原谅自己,工作3-5年后如果还是对测试环境搭建一无所知,面试官会一脸的鄙视. 本篇以最简单的禅道环境搭建为例,学习下 ...