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 ...
随机推荐
- [POJ1655]Balancing Act
思路:DP求树的重心.对于每个结点$i$,$d_i=\displaystyle{\sum_{j\in s(i)}}d_j+1$.删去这个点能得到的最大子树大小即为$\max(\max\limits_{ ...
- BZOJ2090 : [Poi2010]Monotonicity 2
设f[i]表示以i为结尾的最长的合法序列的长度,=号直接维护,<号和>号用两棵树状数组维护即可,时间复杂度$O(n\log n)$. #include<cstdio> #def ...
- 【BZOJ】1854: [Scoi2010]游戏【二分图】
1854: [Scoi2010]游戏 Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 6759 Solved: 2812[Submit][Status] ...
- C语言程序设计I—寒假作业
20188480 http://www.cnblogs.com/arthur-w/
- 移动前端开发和 Web 前端开发的区别是什么
可以分成两部分理解1.服务器端开发,也叫后台开发,这是唯一的,对应不同的平台,他负责数据的分发与存储,和一些逻辑的处理.逻辑处理的多少由业务的复杂程度决定.服务端相对独立,与平台没啥关系. 2..1中 ...
- 使用 IntraWeb (11) - 基本控件之 TIWButton
所在单元及继承链: IWCompButton.TIWButton < TIWCustomControl < TIWBaseHTMLControl < TIWBaseControl & ...
- HDU 3472 HS BDC (混合图的欧拉路径判断)
HS BDC Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- Android笔记之 网络http通信
0.在认识HTTP前先认识URL 在我们认识HTTP之前,有必要先弄清楚URL的组成,比如: http://www.******.com/china/index.htm 它的含义例如以下: 1. ht ...
- 依赖注入(DI)和控制反转(IOC)的理解,写的太好了。
学习过spring框架的人一定都会听过Spring的IoC(控制反转) .DI(依赖注入)这两个概念,对于初学Spring的人来说,总觉得IoC .DI这两个概念是模糊不清的,是很难理解的,今天和大家 ...
- Unity3D实践系列01,创建项目
下载并安装Unity5软件客户端. 打开软件,注册Unity帐号,并用注册帐号登录. 点击"创建Project"按钮. 把项目命名为"My First Unity Pro ...