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 ...
随机推荐
- BZOJ.1061.[NOI2008]志愿者招募(线性规划 对偶原理 单纯形 / 费用流SPFA)
题目链接 线性规划 用\(A_{ij}=0/1\)表示第\(i\)天\(j\)类志愿者能否被招募,\(x_i\)为\(i\)类志愿者招募了多少人,\(need_i\)表示第\(i\)天需要多少人,\( ...
- 【BZOJ-4212】神牛的养成计划 Trie树 + 可持久化Trie树
4212: 神牛的养成计划 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 136 Solved: 27[Submit][Status][Discus ...
- [Java]类的生命周期(上)类的加载和连接[转]
本文来自:曹胜欢博客专栏.转载请注明出处:http://blog.csdn.net/csh624366188 类加载器,顾名思义,类加载器(class loader)用来加载 Java 类到 Java ...
- android studio 使用总结
网站1:http://stormzhang.com/posts.html 网站2:http://blog.csdn.net/hyr83960944/article/details/38388429
- C#——性能计数器
简要Windows性能监视器: 打开Windows性能监视器的步骤如下: 开始→运行→perfmon→确定 在这里我们可以选择添加我们要监控的计数器,比如:cpu使用率.内存使用量等,作为asp.ne ...
- .net core程序部署
前期将一些程序切换到了.net core,本文这里记录下windows 下.net core程序部署相关的方法.有同样需求的朋友可以参考一下,以免少走一些弯路. .net core程序部署主要工作就是 ...
- [Deepin 15] 安装 Java 8、Git、Firefox、SafeEyes(定时提醒休息工具)
一.安装 JDK 8 1.到官网,用 迅雷下载 安装包 (jdk-8u131-linux-x64.tar.gz) 2.解压放到目录 /opt/software/jdk 3.配置环境变量 sudo vi ...
- stanford CS DB 课程 数据库系统实现
http://infolab.stanford.edu/db_pages/classes.html CS145: Introduction to Databases CS245: Databa ...
- iPhone/iPad各种文件路径详解 帮助了解自己的iphone和ipad
以下内容皆为转载分享iPhone里重要的目录路径有哪几个? 1. /private/var/mobile 新刷完的机器,要在这个文件夹下建一个Documents的目录,很多程序都要用到. 2. /pr ...
- WordPress主题开发:WP_Query基本用法
为什么要学WP_Query? wordpress默认会根据网址调用数据,不能满足我们所有建站要求,而WP_Query可以用于查询任何你想要的内容,相当于自定义数据调用. 便于记忆,在讲用法之前我们回顾 ...