Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
woshizhushiqiu
spring-framework
提交
ea3250c8
S
spring-framework
项目概览
woshizhushiqiu
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ea3250c8
编写于
11月 05, 2018
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Explicit notes on class/method-level semantics in class hierarchies
Issue: SPR-17445
上级
b1f5f515
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
27 addition
and
16 deletion
+27
-16
spring-tx/src/main/java/org/springframework/transaction/annotation/Transactional.java
...springframework/transaction/annotation/Transactional.java
+6
-1
src/docs/asciidoc/data-access.adoc
src/docs/asciidoc/data-access.adoc
+21
-15
未找到文件。
spring-tx/src/main/java/org/springframework/transaction/annotation/Transactional.java
浏览文件 @
ea3250c8
...
...
@@ -27,7 +27,12 @@ import org.springframework.core.annotation.AliasFor;
import
org.springframework.transaction.TransactionDefinition
;
/**
* Describes transaction attributes on a method or class.
* Describes a transaction attribute on an individual method or on a class.
*
* <p>At the class level, this annotation applies as a default to all methods of
* the declaring class and its subclasses. Note that it does not apply to ancestor
* classes up the class hierarchy; methods need to be locally redeclared in order
* to participate in a subclass-level annotation.
*
* <p>This annotation type is generally directly comparable to Spring's
* {@link org.springframework.transaction.interceptor.RuleBasedTransactionAttribute}
...
...
src/docs/asciidoc/data-access.adoc
浏览文件 @
ea3250c8
...
...
@@ -1100,8 +1100,19 @@ Consider the following class definition:
----
====
When the preceding POJO is defined as a bean in a Spring IoC container, you can make the bean instance
transactional by adding only one line of XML configuration:
Used at the class level as above, the annotation indicates a default for all methods
of the declaring class (as well as its subclasses). Alternatively, each method can
get annotated individually. Note that a class-level annotation does not apply to
ancestor classes up the class hierarchy; in such a scenario, methods need to be
locally redeclared in order to participate in a subclass-level annotation.
When a POJO class such as the one above is defined as a bean in a Spring context,
you can make the bean instance transactional through an `@EnableTransactionManagement`
annotation in a `@Configuration` class. See the
{api-spring-framework}/transaction/annotation/EnableTransactionManagement.html[javadoc]
for full details.
In XML configuration, the `<tx:annotation-driven/>` tag provides similar convenience:
====
[source,xml,indent=0]
...
...
@@ -1126,6 +1137,7 @@ transactional by adding only one line of XML configuration:
<!-- enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven transaction-manager="txManager"/><!-- a PlatformTransactionManager is still required --> <1>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- (this dependency is defined somewhere else) -->
<property name="dataSource" ref="dataSource"/>
...
...
@@ -1144,11 +1156,6 @@ if the bean name of the `PlatformTransactionManager` that you want to wire in ha
dependency-inject has any other name, you have to use the `transaction-manager` attribute,
as in the preceding example.
NOTE: If you use Java-based configuration, the `@EnableTransactionManagement` annotation
provides equivalent support . You can add the annotation to a `@Configuration` class.
See the {api-spring-framework}/transaction/annotation/EnableTransactionManagement.html[javadoc]
for full details.
.Method visibility and `@Transactional`
****
When you use proxies, you should apply the `@Transactional` annotation only to methods
...
...
@@ -1158,13 +1165,13 @@ method does not exhibit the configured transactional settings. If you need to an
non-public methods, consider using AspectJ (described later).
****
You can
place the `@Transactional` annotation before
an interface definition, a method
You can
apply the `@Transactional` annotation to
an interface definition, a method
on an interface, a class definition, or a public method on a class. However, the
mere presence of the `@Transactional` annotation is not enough to activate the
transactional behavior. The `@Transactional` annotation is merely metadata that can
be
consumed by some runtime infrastructure that is `@Transactional`-aware and that can use
the metadata to configure the appropriate beans with transactional behavior. In the
preceding example, the `<tx:annotation-driven/>` element switches on the
transactional behavior. The `@Transactional` annotation is merely metadata that can
be consumed by some runtime infrastructure that is `@Transactional`-aware and that
can use the metadata to configure the appropriate beans with transactional behavior.
In the
preceding example, the `<tx:annotation-driven/>` element switches on the
transactional behavior.
TIP: The Spring team recommends that you annotate only concrete classes (and methods of
...
...
@@ -1173,9 +1180,8 @@ You certainly can place the `@Transactional` annotation on an interface (or an i
method), but this works only as you would expect it to if you use interface-based
proxies. The fact that Java annotations are not inherited from interfaces means that,
if you use class-based proxies (`proxy-target-class="true"`) or the weaving-based
aspect (`mode="aspectj"`), the transaction settings are not recognized by the
proxying and weaving infrastructure, and the object is not wrapped in a
transactional proxy, which would be decidedly bad.
aspect (`mode="aspectj"`), the transaction settings are not recognized by the proxying
and weaving infrastructure, and the object is not wrapped in a transactional proxy.
NOTE: In proxy mode (which is the default), only external method calls coming in through
the proxy are intercepted. This means that self-invocation (in effect, a method within
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录