Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
6b7c1d72
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
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,体验更适合开发者的 AI 搜索 >>
提交
6b7c1d72
编写于
6月 12, 2015
作者:
S
Sam Brannen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduce alias for 'value' attribute in @Transactional
Issue: SPR-11393
上级
6fc38831
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
49 addition
and
36 deletion
+49
-36
spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTests.java
...esAndTransactionManagersTransactionalSqlScriptsTests.java
+3
-3
spring-tx/src/main/java/org/springframework/transaction/annotation/Transactional.java
...springframework/transaction/annotation/Transactional.java
+12
-1
spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionNamespaceHandlerTests.java
...nnotation/AnnotationTransactionNamespaceHandlerTests.java
+5
-0
spring-tx/src/test/java/org/springframework/transaction/annotation/EnableTransactionManagementTests.java
...nsaction/annotation/EnableTransactionManagementTests.java
+29
-32
未找到文件。
spring-test/src/test/java/org/springframework/test/context/jdbc/MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTests.java
浏览文件 @
6b7c1d72
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
5
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -48,7 +48,7 @@ import static org.junit.Assert.*;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@ContextConfiguration
@DirtiesContext
@Transactional
(
"txMgr1"
)
@Transactional
(
transactionManager
=
"txMgr1"
)
@SqlConfig
(
dataSource
=
"dataSource1"
,
transactionManager
=
"txMgr1"
)
public
class
MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTests
{
...
...
@@ -66,7 +66,7 @@ public class MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTes
}
@Test
@Transactional
(
"txMgr2"
)
@Transactional
(
transactionManager
=
"txMgr2"
)
@Sql
(
scripts
=
"data-add-catbert.sql"
,
config
=
@SqlConfig
(
dataSource
=
"dataSource2"
,
transactionManager
=
"txMgr2"
))
public
void
database2
()
{
assertUsers
(
new
JdbcTemplate
(
dataSource2
),
"Dilbert"
,
"Catbert"
);
...
...
spring-tx/src/main/java/org/springframework/transaction/annotation/Transactional.java
浏览文件 @
6b7c1d72
...
...
@@ -23,6 +23,7 @@ import java.lang.annotation.Retention;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
import
org.springframework.core.annotation.AliasFor
;
import
org.springframework.transaction.TransactionDefinition
;
/**
...
...
@@ -55,14 +56,24 @@ import org.springframework.transaction.TransactionDefinition;
@Documented
public
@interface
Transactional
{
/**
* Alias for {@link #transactionManager}.
* @see #transactionManager
*/
@AliasFor
(
attribute
=
"transactionManager"
)
String
value
()
default
""
;
/**
* A <em>qualifier</em> value for the specified transaction.
* <p>May be used to determine the target transaction manager,
* matching the qualifier value (or the bean name) of a specific
* {@link org.springframework.transaction.PlatformTransactionManager}
* bean definition.
* @since 4.2
* @see #value
*/
String
value
()
default
""
;
@AliasFor
(
attribute
=
"value"
)
String
transactionManager
()
default
""
;
/**
* The transaction propagation type.
...
...
spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionNamespaceHandlerTests.java
浏览文件 @
6b7c1d72
...
...
@@ -37,6 +37,7 @@ import org.springframework.transaction.event.TransactionalEventListenerFactory;
/**
* @author Rob Harrop
* @author Juergen Hoeller
* @author Sam Brannen
*/
public
class
AnnotationTransactionNamespaceHandlerTests
extends
TestCase
{
...
...
@@ -129,6 +130,10 @@ public class AnnotationTransactionNamespaceHandlerTests extends TestCase {
public
void
saveQualifiedFoo
()
{
}
@Transactional
(
transactionManager
=
"qualifiedTransactionManager"
)
public
void
saveQualifiedFooWithAttributeAlias
()
{
}
@Transactional
public
void
exceptional
(
Throwable
t
)
throws
Throwable
{
throw
t
;
...
...
spring-tx/src/test/java/org/springframework/transaction/annotation/EnableTransactionManagementTests.java
浏览文件 @
6b7c1d72
...
...
@@ -17,6 +17,7 @@
package
org.springframework.transaction.annotation
;
import
java.util.Map
;
import
javax.annotation.PostConstruct
;
import
org.junit.Test
;
...
...
@@ -43,52 +44,49 @@ import static org.junit.Assert.*;
*
* @author Chris Beams
* @author Stephane Nicoll
* @author Sam Brannen
* @since 3.1
*/
public
class
EnableTransactionManagementTests
{
@Test
public
void
transactionProxyIsCreated
()
{
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
();
ctx
.
register
(
EnableTxConfig
.
class
,
TxManagerConfig
.
class
);
ctx
.
refresh
();
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
(
EnableTxConfig
.
class
,
TxManagerConfig
.
class
);
TransactionalTestBean
bean
=
ctx
.
getBean
(
TransactionalTestBean
.
class
);
assertT
hat
(
"testBean is not a proxy"
,
AopUtils
.
isAopProxy
(
bean
),
is
(
true
));
assertT
rue
(
"testBean is not a proxy"
,
AopUtils
.
isAopProxy
(
bean
));
Map
<?,?>
services
=
ctx
.
getBeansWithAnnotation
(
Service
.
class
);
assertThat
(
"Stereotype annotation not visible"
,
services
.
containsKey
(
"testBean"
),
is
(
true
));
assertTrue
(
"Stereotype annotation not visible"
,
services
.
containsKey
(
"testBean"
));
ctx
.
close
();
}
@Test
public
void
transactionProxyIsCreatedWithEnableOnSuperclass
()
{
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
();
ctx
.
register
(
InheritedEnableTxConfig
.
class
,
TxManagerConfig
.
class
);
ctx
.
refresh
();
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
(
InheritedEnableTxConfig
.
class
,
TxManagerConfig
.
class
);
TransactionalTestBean
bean
=
ctx
.
getBean
(
TransactionalTestBean
.
class
);
assertT
hat
(
"testBean is not a proxy"
,
AopUtils
.
isAopProxy
(
bean
),
is
(
true
));
assertT
rue
(
"testBean is not a proxy"
,
AopUtils
.
isAopProxy
(
bean
));
Map
<?,?>
services
=
ctx
.
getBeansWithAnnotation
(
Service
.
class
);
assertThat
(
"Stereotype annotation not visible"
,
services
.
containsKey
(
"testBean"
),
is
(
true
));
assertTrue
(
"Stereotype annotation not visible"
,
services
.
containsKey
(
"testBean"
));
ctx
.
close
();
}
@Test
public
void
txManagerIsResolvedOnInvocationOfTransactionalMethod
()
{
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
();
ctx
.
register
(
EnableTxConfig
.
class
,
TxManagerConfig
.
class
);
ctx
.
refresh
();
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
(
EnableTxConfig
.
class
,
TxManagerConfig
.
class
);
TransactionalTestBean
bean
=
ctx
.
getBean
(
TransactionalTestBean
.
class
);
// invoke a transactional method, causing the PlatformTransactionManager bean to be resolved.
bean
.
findAllFoos
();
ctx
.
close
();
}
@Test
public
void
txManagerIsResolvedCorrectlyWhenMultipleManagersArePresent
()
{
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
();
ctx
.
register
(
EnableTxConfig
.
class
,
MultiTxManagerConfig
.
class
);
ctx
.
refresh
();
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
(
EnableTxConfig
.
class
,
MultiTxManagerConfig
.
class
);
TransactionalTestBean
bean
=
ctx
.
getBean
(
TransactionalTestBean
.
class
);
// invoke a transactional method, causing the PlatformTransactionManager bean to be resolved.
bean
.
findAllFoos
();
ctx
.
close
();
}
/**
...
...
@@ -103,33 +101,35 @@ public class EnableTransactionManagementTests {
"Do you actually have org.springframework.aspects on the classpath?"
);
}
catch
(
Exception
ex
)
{
assertThat
(
ex
.
getMessage
()
.
contains
(
"AspectJTransactionManagementConfiguration"
),
is
(
true
));
assertThat
(
ex
.
getMessage
()
,
containsString
(
"AspectJTransactionManagementConfiguration"
));
}
}
@Test
public
void
transactionalEventListenerRegisteredProperly
()
{
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
();
ctx
.
register
(
EnableTxConfig
.
class
);
ctx
.
refresh
();
assertTrue
(
ctx
.
containsBean
(
TransactionManagementConfigUtils
.
TRANSACTIONAL_EVENT_LISTENER_FACTORY_BEAN_NAME
));
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
(
EnableTxConfig
.
class
);
assertTrue
(
ctx
.
containsBean
(
TransactionManagementConfigUtils
.
TRANSACTIONAL_EVENT_LISTENER_FACTORY_BEAN_NAME
));
assertEquals
(
1
,
ctx
.
getBeansOfType
(
TransactionalEventListenerFactory
.
class
).
size
());
ctx
.
close
();
}
@Test
public
void
spr11915
()
{
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
(
Spr11915Config
.
class
);
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
(
Spr11915Config
.
class
);
TransactionalTestBean
bean
=
ctx
.
getBean
(
TransactionalTestBean
.
class
);
bean
.
saveQualifiedFoo
(
);
CallCountingTransactionManager
txManager
=
ctx
.
getBean
(
"qualifiedTransactionManager"
,
CallCountingTransactionManager
.
class
);
CallCountingTransactionManager
txManager
=
ctx
.
getBean
(
"qualifiedTransactionManager"
,
CallCountingTransactionManager
.
class
);
bean
.
saveQualifiedFoo
();
assertThat
(
txManager
.
begun
,
equalTo
(
1
));
assertThat
(
txManager
.
commits
,
equalTo
(
1
));
assertThat
(
txManager
.
rollbacks
,
equalTo
(
0
));
bean
.
saveQualifiedFooWithAttributeAlias
();
assertThat
(
txManager
.
begun
,
equalTo
(
2
));
assertThat
(
txManager
.
commits
,
equalTo
(
2
));
assertThat
(
txManager
.
rollbacks
,
equalTo
(
0
));
ctx
.
close
();
}
...
...
@@ -138,12 +138,10 @@ public class EnableTransactionManagementTests {
static
class
EnableTxConfig
{
}
@Configuration
static
class
InheritedEnableTxConfig
extends
EnableTxConfig
{
}
@Configuration
@EnableTransactionManagement
(
mode
=
AdviceMode
.
ASPECTJ
)
static
class
EnableAspectJTxConfig
{
...
...
@@ -168,7 +166,6 @@ public class EnableTransactionManagementTests {
}
}
@Configuration
static
class
TxManagerConfig
{
...
...
@@ -184,7 +181,6 @@ public class EnableTransactionManagementTests {
}
@Configuration
static
class
MultiTxManagerConfig
extends
TxManagerConfig
implements
TransactionManagementConfigurer
{
...
...
@@ -198,4 +194,5 @@ public class EnableTransactionManagementTests {
return
txManager2
();
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录