Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
7cf98261
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 搜索 >>
提交
7cf98261
编写于
8月 08, 2018
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing
上级
247ec572
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
77 addition
and
54 deletion
+77
-54
spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java
...aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java
+2
-2
spring-context/src/main/java/org/springframework/cache/annotation/AnnotationCacheOperationSource.java
...work/cache/annotation/AnnotationCacheOperationSource.java
+7
-2
spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigUtils.java
...ngframework/context/annotation/AnnotationConfigUtils.java
+2
-1
spring-context/src/main/java/org/springframework/context/event/DefaultEventListenerFactory.java
...gframework/context/event/DefaultEventListenerFactory.java
+6
-3
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HandlerMethodAnnotationDetectionTests.java
...hod/annotation/HandlerMethodAnnotationDetectionTests.java
+22
-27
src/test/java/org/springframework/cache/annotation/EnableCachingIntegrationTests.java
...ework/cache/annotation/EnableCachingIntegrationTests.java
+7
-1
src/test/java/org/springframework/transaction/annotation/EnableTransactionManagementIntegrationTests.java
...notation/EnableTransactionManagementIntegrationTests.java
+31
-18
未找到文件。
spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java
浏览文件 @
7cf98261
...
@@ -130,8 +130,8 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
...
@@ -130,8 +130,8 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
protected
static
AspectJAnnotation
<?>
findAspectJAnnotationOnMethod
(
Method
method
)
{
protected
static
AspectJAnnotation
<?>
findAspectJAnnotationOnMethod
(
Method
method
)
{
Class
<?>[]
classesToLookFor
=
new
Class
<?>[]
{
Class
<?>[]
classesToLookFor
=
new
Class
<?>[]
{
Before
.
class
,
Around
.
class
,
After
.
class
,
AfterReturning
.
class
,
AfterThrowing
.
class
,
Pointcut
.
class
};
Before
.
class
,
Around
.
class
,
After
.
class
,
AfterReturning
.
class
,
AfterThrowing
.
class
,
Pointcut
.
class
};
for
(
Class
<?>
c
:
classesToLookFor
)
{
for
(
Class
<?>
c
lazz
:
classesToLookFor
)
{
AspectJAnnotation
<?>
foundAnnotation
=
findAnnotation
(
method
,
(
Class
<
Annotation
>)
c
);
AspectJAnnotation
<?>
foundAnnotation
=
findAnnotation
(
method
,
(
Class
<
Annotation
>)
c
lazz
);
if
(
foundAnnotation
!=
null
)
{
if
(
foundAnnotation
!=
null
)
{
return
foundAnnotation
;
return
foundAnnotation
;
}
}
...
...
spring-context/src/main/java/org/springframework/cache/annotation/AnnotationCacheOperationSource.java
浏览文件 @
7cf98261
...
@@ -131,9 +131,14 @@ public class AnnotationCacheOperationSource extends AbstractFallbackCacheOperati
...
@@ -131,9 +131,14 @@ public class AnnotationCacheOperationSource extends AbstractFallbackCacheOperati
Collection
<
CacheOperation
>
annOps
=
provider
.
getCacheOperations
(
annotationParser
);
Collection
<
CacheOperation
>
annOps
=
provider
.
getCacheOperations
(
annotationParser
);
if
(
annOps
!=
null
)
{
if
(
annOps
!=
null
)
{
if
(
ops
==
null
)
{
if
(
ops
==
null
)
{
ops
=
new
ArrayList
<>();
ops
=
annOps
;
}
else
{
Collection
<
CacheOperation
>
combined
=
new
ArrayList
<>(
ops
.
size
()
+
annOps
.
size
());
combined
.
addAll
(
ops
);
combined
.
addAll
(
annOps
);
ops
=
combined
;
}
}
ops
.
addAll
(
annOps
);
}
}
}
}
return
ops
;
return
ops
;
...
...
spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigUtils.java
浏览文件 @
7cf98261
...
@@ -159,7 +159,7 @@ public abstract class AnnotationConfigUtils {
...
@@ -159,7 +159,7 @@ public abstract class AnnotationConfigUtils {
}
}
}
}
Set
<
BeanDefinitionHolder
>
beanDefs
=
new
LinkedHashSet
<>(
4
);
Set
<
BeanDefinitionHolder
>
beanDefs
=
new
LinkedHashSet
<>(
8
);
if
(!
registry
.
containsBeanDefinition
(
CONFIGURATION_ANNOTATION_PROCESSOR_BEAN_NAME
))
{
if
(!
registry
.
containsBeanDefinition
(
CONFIGURATION_ANNOTATION_PROCESSOR_BEAN_NAME
))
{
RootBeanDefinition
def
=
new
RootBeanDefinition
(
ConfigurationClassPostProcessor
.
class
);
RootBeanDefinition
def
=
new
RootBeanDefinition
(
ConfigurationClassPostProcessor
.
class
);
...
@@ -200,6 +200,7 @@ public abstract class AnnotationConfigUtils {
...
@@ -200,6 +200,7 @@ public abstract class AnnotationConfigUtils {
def
.
setSource
(
source
);
def
.
setSource
(
source
);
beanDefs
.
add
(
registerPostProcessor
(
registry
,
def
,
EVENT_LISTENER_PROCESSOR_BEAN_NAME
));
beanDefs
.
add
(
registerPostProcessor
(
registry
,
def
,
EVENT_LISTENER_PROCESSOR_BEAN_NAME
));
}
}
if
(!
registry
.
containsBeanDefinition
(
EVENT_LISTENER_FACTORY_BEAN_NAME
))
{
if
(!
registry
.
containsBeanDefinition
(
EVENT_LISTENER_FACTORY_BEAN_NAME
))
{
RootBeanDefinition
def
=
new
RootBeanDefinition
(
DefaultEventListenerFactory
.
class
);
RootBeanDefinition
def
=
new
RootBeanDefinition
(
DefaultEventListenerFactory
.
class
);
def
.
setSource
(
source
);
def
.
setSource
(
source
);
...
...
spring-context/src/main/java/org/springframework/context/event/DefaultEventListenerFactory.java
浏览文件 @
7cf98261
...
@@ -24,6 +24,7 @@ import org.springframework.core.Ordered;
...
@@ -24,6 +24,7 @@ import org.springframework.core.Ordered;
/**
/**
* Default {@link EventListenerFactory} implementation that supports the
* Default {@link EventListenerFactory} implementation that supports the
* regular {@link EventListener} annotation.
* regular {@link EventListener} annotation.
*
* <p>Used as "catch-all" implementation by default.
* <p>Used as "catch-all" implementation by default.
*
*
* @author Stephane Nicoll
* @author Stephane Nicoll
...
@@ -33,14 +34,16 @@ public class DefaultEventListenerFactory implements EventListenerFactory, Ordere
...
@@ -33,14 +34,16 @@ public class DefaultEventListenerFactory implements EventListenerFactory, Ordere
private
int
order
=
LOWEST_PRECEDENCE
;
private
int
order
=
LOWEST_PRECEDENCE
;
public
void
setOrder
(
int
order
)
{
this
.
order
=
order
;
}
@Override
@Override
public
int
getOrder
()
{
public
int
getOrder
()
{
return
this
.
order
;
return
this
.
order
;
}
}
public
void
setOrder
(
int
order
)
{
this
.
order
=
order
;
}
public
boolean
supportsMethod
(
Method
method
)
{
public
boolean
supportsMethod
(
Method
method
)
{
return
true
;
return
true
;
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/HandlerMethodAnnotationDetectionTests.java
浏览文件 @
7cf98261
...
@@ -67,20 +67,20 @@ public class HandlerMethodAnnotationDetectionTests {
...
@@ -67,20 +67,20 @@ public class HandlerMethodAnnotationDetectionTests {
public
static
Object
[][]
handlerTypes
()
{
public
static
Object
[][]
handlerTypes
()
{
return
new
Object
[][]
{
return
new
Object
[][]
{
{
SimpleController
.
class
,
true
},
// CGL
ib
proxy
{
SimpleController
.
class
,
true
},
// CGL
IB
proxy
{
SimpleController
.
class
,
false
},
{
SimpleController
.
class
,
false
},
{
AbstractClassController
.
class
,
true
},
// CGL
ib
proxy
{
AbstractClassController
.
class
,
true
},
// CGL
IB
proxy
{
AbstractClassController
.
class
,
false
},
{
AbstractClassController
.
class
,
false
},
{
ParameterizedAbstractClassController
.
class
,
true
},
// CGL
ib
proxy
{
ParameterizedAbstractClassController
.
class
,
true
},
// CGL
IB
proxy
{
ParameterizedAbstractClassController
.
class
,
false
},
{
ParameterizedAbstractClassController
.
class
,
false
},
{
ParameterizedSubclassOverridesDefaultMappings
.
class
,
true
},
// CGL
ib
proxy
{
ParameterizedSubclassOverridesDefaultMappings
.
class
,
true
},
// CGL
IB
proxy
{
ParameterizedSubclassOverridesDefaultMappings
.
class
,
false
},
{
ParameterizedSubclassOverridesDefaultMappings
.
class
,
false
},
// TODO [SPR-9517] Enable ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass test cases
// TODO [SPR-9517] Enable ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass test cases
// { ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass.class, true }, // CGL
ib
proxy
// { ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass.class, true }, // CGL
IB
proxy
// { ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass.class, false },
// { ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass.class, false },
{
InterfaceController
.
class
,
true
},
// JDK dynamic proxy
{
InterfaceController
.
class
,
true
},
// JDK dynamic proxy
...
@@ -88,7 +88,7 @@ public class HandlerMethodAnnotationDetectionTests {
...
@@ -88,7 +88,7 @@ public class HandlerMethodAnnotationDetectionTests {
{
ParameterizedInterfaceController
.
class
,
false
},
// no AOP
{
ParameterizedInterfaceController
.
class
,
false
},
// no AOP
{
SupportClassController
.
class
,
true
},
// CGL
ib
proxy
{
SupportClassController
.
class
,
true
},
// CGL
IB
proxy
{
SupportClassController
.
class
,
false
}
{
SupportClassController
.
class
,
false
}
};
};
...
@@ -100,7 +100,8 @@ public class HandlerMethodAnnotationDetectionTests {
...
@@ -100,7 +100,8 @@ public class HandlerMethodAnnotationDetectionTests {
private
ExceptionHandlerExceptionResolver
exceptionResolver
=
new
ExceptionHandlerExceptionResolver
();
private
ExceptionHandlerExceptionResolver
exceptionResolver
=
new
ExceptionHandlerExceptionResolver
();
public
HandlerMethodAnnotationDetectionTests
(
final
Class
<?>
controllerType
,
boolean
useAutoProxy
)
{
public
HandlerMethodAnnotationDetectionTests
(
Class
<?>
controllerType
,
boolean
useAutoProxy
)
{
GenericWebApplicationContext
context
=
new
GenericWebApplicationContext
();
GenericWebApplicationContext
context
=
new
GenericWebApplicationContext
();
context
.
registerBeanDefinition
(
"controller"
,
new
RootBeanDefinition
(
controllerType
));
context
.
registerBeanDefinition
(
"controller"
,
new
RootBeanDefinition
(
controllerType
));
context
.
registerBeanDefinition
(
"handlerMapping"
,
new
RootBeanDefinition
(
RequestMappingHandlerMapping
.
class
));
context
.
registerBeanDefinition
(
"handlerMapping"
,
new
RootBeanDefinition
(
RequestMappingHandlerMapping
.
class
));
...
@@ -120,12 +121,6 @@ public class HandlerMethodAnnotationDetectionTests {
...
@@ -120,12 +121,6 @@ public class HandlerMethodAnnotationDetectionTests {
context
.
close
();
context
.
close
();
}
}
class
TestPointcut
extends
StaticMethodMatcherPointcut
{
@Override
public
boolean
matches
(
Method
method
,
@Nullable
Class
<?>
clazz
)
{
return
method
.
getName
().
equals
(
"hashCode"
);
}
}
@Test
@Test
public
void
testRequestMappingMethod
()
throws
Exception
{
public
void
testRequestMappingMethod
()
throws
Exception
{
...
@@ -203,9 +198,9 @@ public class HandlerMethodAnnotationDetectionTests {
...
@@ -203,9 +198,9 @@ public class HandlerMethodAnnotationDetectionTests {
public
abstract
String
handleException
(
Exception
exception
);
public
abstract
String
handleException
(
Exception
exception
);
}
}
/**
/**
* CONTROLLER WITH ABSTRACT CLASS
* CONTROLLER WITH ABSTRACT CLASS
*
* <p>All annotations can be on methods in the abstract class except parameter annotations.
* <p>All annotations can be on methods in the abstract class except parameter annotations.
*/
*/
static
class
AbstractClassController
extends
MappingAbstractClass
{
static
class
AbstractClassController
extends
MappingAbstractClass
{
...
@@ -232,10 +227,10 @@ public class HandlerMethodAnnotationDetectionTests {
...
@@ -232,10 +227,10 @@ public class HandlerMethodAnnotationDetectionTests {
}
}
}
}
// SPR-9374
// SPR-9374
@RequestMapping
@RequestMapping
static
interface
MappingInterface
{
interface
MappingInterface
{
@InitBinder
@InitBinder
void
initBinder
(
WebDataBinder
dataBinder
,
@RequestParam
(
"datePattern"
)
String
thePattern
);
void
initBinder
(
WebDataBinder
dataBinder
,
@RequestParam
(
"datePattern"
)
String
thePattern
);
...
@@ -252,14 +247,11 @@ public class HandlerMethodAnnotationDetectionTests {
...
@@ -252,14 +247,11 @@ public class HandlerMethodAnnotationDetectionTests {
String
handleException
(
Exception
exception
);
String
handleException
(
Exception
exception
);
}
}
/**
/**
* CONTROLLER WITH INTERFACE
* CONTROLLER WITH INTERFACE
*
* <p>JDK Dynamic proxy: All annotations must be on the interface.
* JDK Dynamic proxy:
* <p>Without AOP: Annotations can be on interface methods except parameter annotations.
* All annotations must be on the interface.
*
* Without AOP:
* Annotations can be on interface methods except parameter annotations.
*/
*/
static
class
InterfaceController
implements
MappingInterface
{
static
class
InterfaceController
implements
MappingInterface
{
...
@@ -304,9 +296,9 @@ public class HandlerMethodAnnotationDetectionTests {
...
@@ -304,9 +296,9 @@ public class HandlerMethodAnnotationDetectionTests {
public
abstract
String
handleException
(
Exception
exception
);
public
abstract
String
handleException
(
Exception
exception
);
}
}
/**
/**
* CONTROLLER WITH PARAMETERIZED BASE CLASS
* CONTROLLER WITH PARAMETERIZED BASE CLASS
*
* <p>All annotations can be on methods in the abstract class except parameter annotations.
* <p>All annotations can be on methods in the abstract class except parameter annotations.
*/
*/
static
class
ParameterizedAbstractClassController
extends
MappingGenericAbstractClass
<
String
,
Date
,
Date
>
{
static
class
ParameterizedAbstractClassController
extends
MappingGenericAbstractClass
<
String
,
Date
,
Date
>
{
...
@@ -333,6 +325,7 @@ public class HandlerMethodAnnotationDetectionTests {
...
@@ -333,6 +325,7 @@ public class HandlerMethodAnnotationDetectionTests {
}
}
}
}
@Controller
@Controller
static
abstract
class
MappedGenericAbstractClassWithConcreteImplementations
<
A
,
B
,
C
>
{
static
abstract
class
MappedGenericAbstractClassWithConcreteImplementations
<
A
,
B
,
C
>
{
...
@@ -353,6 +346,7 @@ public class HandlerMethodAnnotationDetectionTests {
...
@@ -353,6 +346,7 @@ public class HandlerMethodAnnotationDetectionTests {
public
abstract
String
handleException
(
Exception
exception
);
public
abstract
String
handleException
(
Exception
exception
);
}
}
static
class
ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass
extends
static
class
ParameterizedSubclassDoesNotOverrideConcreteImplementationsFromGenericAbstractSuperclass
extends
MappedGenericAbstractClassWithConcreteImplementations
<
String
,
Date
,
Date
>
{
MappedGenericAbstractClassWithConcreteImplementations
<
String
,
Date
,
Date
>
{
...
@@ -375,6 +369,7 @@ public class HandlerMethodAnnotationDetectionTests {
...
@@ -375,6 +369,7 @@ public class HandlerMethodAnnotationDetectionTests {
}
}
}
}
@Controller
@Controller
static
abstract
class
GenericAbstractClassDeclaresDefaultMappings
<
A
,
B
,
C
>
{
static
abstract
class
GenericAbstractClassDeclaresDefaultMappings
<
A
,
B
,
C
>
{
...
@@ -395,6 +390,7 @@ public class HandlerMethodAnnotationDetectionTests {
...
@@ -395,6 +390,7 @@ public class HandlerMethodAnnotationDetectionTests {
public
abstract
String
handleException
(
Exception
exception
);
public
abstract
String
handleException
(
Exception
exception
);
}
}
static
class
ParameterizedSubclassOverridesDefaultMappings
static
class
ParameterizedSubclassOverridesDefaultMappings
extends
GenericAbstractClassDeclaresDefaultMappings
<
String
,
Date
,
Date
>
{
extends
GenericAbstractClassDeclaresDefaultMappings
<
String
,
Date
,
Date
>
{
...
@@ -425,8 +421,9 @@ public class HandlerMethodAnnotationDetectionTests {
...
@@ -425,8 +421,9 @@ public class HandlerMethodAnnotationDetectionTests {
}
}
}
}
@RequestMapping
@RequestMapping
static
interface
MappingGenericInterface
<
A
,
B
,
C
>
{
interface
MappingGenericInterface
<
A
,
B
,
C
>
{
@InitBinder
@InitBinder
void
initBinder
(
WebDataBinder
dataBinder
,
A
thePattern
);
void
initBinder
(
WebDataBinder
dataBinder
,
A
thePattern
);
...
@@ -443,11 +440,10 @@ public class HandlerMethodAnnotationDetectionTests {
...
@@ -443,11 +440,10 @@ public class HandlerMethodAnnotationDetectionTests {
String
handleException
(
Exception
exception
);
String
handleException
(
Exception
exception
);
}
}
/**
/**
* CONTROLLER WITH PARAMETERIZED INTERFACE
* CONTROLLER WITH PARAMETERIZED INTERFACE
*
* <p>All annotations can be on interface except parameter annotations.
* <p>All annotations can be on interface except parameter annotations.
*
* <p>Cannot be used as JDK dynamic proxy since parameterized interface does not contain type information.
* <p>Cannot be used as JDK dynamic proxy since parameterized interface does not contain type information.
*/
*/
static
class
ParameterizedInterfaceController
implements
MappingGenericInterface
<
String
,
Date
,
Date
>
{
static
class
ParameterizedInterfaceController
implements
MappingGenericInterface
<
String
,
Date
,
Date
>
{
...
@@ -483,7 +479,6 @@ public class HandlerMethodAnnotationDetectionTests {
...
@@ -483,7 +479,6 @@ public class HandlerMethodAnnotationDetectionTests {
/**
/**
* SPR-8248
* SPR-8248
*
* <p>Support class contains all annotations. Subclass has type-level @{@link RequestMapping}.
* <p>Support class contains all annotations. Subclass has type-level @{@link RequestMapping}.
*/
*/
@Controller
@Controller
...
...
src/test/java/org/springframework/cache/annotation/EnableCachingIntegrationTests.java
浏览文件 @
7cf98261
/*
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
8
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -70,6 +70,7 @@ public class EnableCachingIntegrationTests {
...
@@ -70,6 +70,7 @@ public class EnableCachingIntegrationTests {
}
}
}
}
private
void
assertCacheProxying
(
AnnotationConfigApplicationContext
ctx
)
{
private
void
assertCacheProxying
(
AnnotationConfigApplicationContext
ctx
)
{
FooRepository
repo
=
ctx
.
getBean
(
FooRepository
.
class
);
FooRepository
repo
=
ctx
.
getBean
(
FooRepository
.
class
);
...
@@ -89,6 +90,7 @@ public class EnableCachingIntegrationTests {
...
@@ -89,6 +90,7 @@ public class EnableCachingIntegrationTests {
@Configuration
@Configuration
@EnableCaching
(
proxyTargetClass
=
true
)
@EnableCaching
(
proxyTargetClass
=
true
)
static
class
ProxyTargetClassCachingConfig
{
static
class
ProxyTargetClassCachingConfig
{
@Bean
@Bean
CacheManager
mgr
()
{
CacheManager
mgr
()
{
return
new
NoOpCacheManager
();
return
new
NoOpCacheManager
();
...
@@ -98,6 +100,7 @@ public class EnableCachingIntegrationTests {
...
@@ -98,6 +100,7 @@ public class EnableCachingIntegrationTests {
@Configuration
@Configuration
static
class
Config
{
static
class
Config
{
@Bean
@Bean
FooRepository
fooRepository
()
{
FooRepository
fooRepository
()
{
return
new
DummyFooRepository
();
return
new
DummyFooRepository
();
...
@@ -108,6 +111,7 @@ public class EnableCachingIntegrationTests {
...
@@ -108,6 +111,7 @@ public class EnableCachingIntegrationTests {
@Configuration
@Configuration
@EnableCaching
(
mode
=
AdviceMode
.
ASPECTJ
)
@EnableCaching
(
mode
=
AdviceMode
.
ASPECTJ
)
static
class
AspectJCacheConfig
{
static
class
AspectJCacheConfig
{
@Bean
@Bean
CacheManager
cacheManager
()
{
CacheManager
cacheManager
()
{
return
new
NoOpCacheManager
();
return
new
NoOpCacheManager
();
...
@@ -116,6 +120,7 @@ public class EnableCachingIntegrationTests {
...
@@ -116,6 +120,7 @@ public class EnableCachingIntegrationTests {
interface
FooRepository
{
interface
FooRepository
{
List
<
Object
>
findAll
();
List
<
Object
>
findAll
();
}
}
...
@@ -129,4 +134,5 @@ public class EnableCachingIntegrationTests {
...
@@ -129,4 +134,5 @@ public class EnableCachingIntegrationTests {
return
Collections
.
emptyList
();
return
Collections
.
emptyList
();
}
}
}
}
}
}
src/test/java/org/springframework/transaction/annotation/EnableTransactionManagementIntegrationTests.java
浏览文件 @
7cf98261
...
@@ -166,10 +166,30 @@ public class EnableTransactionManagementIntegrationTests {
...
@@ -166,10 +166,30 @@ public class EnableTransactionManagementIntegrationTests {
}
}
private
void
assertTxProxying
(
AnnotationConfigApplicationContext
ctx
)
{
FooRepository
repo
=
ctx
.
getBean
(
FooRepository
.
class
);
boolean
isTxProxy
=
false
;
if
(
AopUtils
.
isAopProxy
(
repo
))
{
for
(
Advisor
advisor
:
((
Advised
)
repo
).
getAdvisors
())
{
if
(
advisor
instanceof
BeanFactoryTransactionAttributeSourceAdvisor
)
{
isTxProxy
=
true
;
break
;
}
}
}
assertTrue
(
"FooRepository is not a TX proxy"
,
isTxProxy
);
// trigger a transaction
repo
.
findAll
();
}
@Configuration
@Configuration
@EnableTransactionManagement
@EnableTransactionManagement
@ImportResource
(
"org/springframework/transaction/annotation/enable-caching.xml"
)
@ImportResource
(
"org/springframework/transaction/annotation/enable-caching.xml"
)
static
class
EnableTxAndCachingConfig
{
static
class
EnableTxAndCachingConfig
{
@Bean
@Bean
public
PlatformTransactionManager
txManager
()
{
public
PlatformTransactionManager
txManager
()
{
return
new
CallCountingTransactionManager
();
return
new
CallCountingTransactionManager
();
...
@@ -194,6 +214,7 @@ public class EnableTransactionManagementIntegrationTests {
...
@@ -194,6 +214,7 @@ public class EnableTransactionManagementIntegrationTests {
@Configuration
@Configuration
@EnableTransactionManagement
@EnableTransactionManagement
static
class
ImplicitTxManagerConfig
{
static
class
ImplicitTxManagerConfig
{
@Bean
@Bean
public
PlatformTransactionManager
txManager
()
{
public
PlatformTransactionManager
txManager
()
{
return
new
CallCountingTransactionManager
();
return
new
CallCountingTransactionManager
();
...
@@ -209,6 +230,7 @@ public class EnableTransactionManagementIntegrationTests {
...
@@ -209,6 +230,7 @@ public class EnableTransactionManagementIntegrationTests {
@Configuration
@Configuration
@EnableTransactionManagement
@EnableTransactionManagement
static
class
ExplicitTxManagerConfig
implements
TransactionManagementConfigurer
{
static
class
ExplicitTxManagerConfig
implements
TransactionManagementConfigurer
{
@Bean
@Bean
public
PlatformTransactionManager
txManager1
()
{
public
PlatformTransactionManager
txManager1
()
{
return
new
CallCountingTransactionManager
();
return
new
CallCountingTransactionManager
();
...
@@ -230,28 +252,11 @@ public class EnableTransactionManagementIntegrationTests {
...
@@ -230,28 +252,11 @@ public class EnableTransactionManagementIntegrationTests {
}
}
}
}
private
void
assertTxProxying
(
AnnotationConfigApplicationContext
ctx
)
{
FooRepository
repo
=
ctx
.
getBean
(
FooRepository
.
class
);
boolean
isTxProxy
=
false
;
if
(
AopUtils
.
isAopProxy
(
repo
))
{
for
(
Advisor
advisor
:
((
Advised
)
repo
).
getAdvisors
())
{
if
(
advisor
instanceof
BeanFactoryTransactionAttributeSourceAdvisor
)
{
isTxProxy
=
true
;
break
;
}
}
}
assertTrue
(
"FooRepository is not a TX proxy"
,
isTxProxy
);
// trigger a transaction
repo
.
findAll
();
}
@Configuration
@Configuration
@EnableTransactionManagement
@EnableTransactionManagement
static
class
DefaultTxManagerNameConfig
{
static
class
DefaultTxManagerNameConfig
{
@Bean
@Bean
PlatformTransactionManager
transactionManager
(
DataSource
dataSource
)
{
PlatformTransactionManager
transactionManager
(
DataSource
dataSource
)
{
return
new
DataSourceTransactionManager
(
dataSource
);
return
new
DataSourceTransactionManager
(
dataSource
);
...
@@ -262,6 +267,7 @@ public class EnableTransactionManagementIntegrationTests {
...
@@ -262,6 +267,7 @@ public class EnableTransactionManagementIntegrationTests {
@Configuration
@Configuration
@EnableTransactionManagement
@EnableTransactionManagement
static
class
CustomTxManagerNameConfig
{
static
class
CustomTxManagerNameConfig
{
@Bean
@Bean
PlatformTransactionManager
txManager
(
DataSource
dataSource
)
{
PlatformTransactionManager
txManager
(
DataSource
dataSource
)
{
return
new
DataSourceTransactionManager
(
dataSource
);
return
new
DataSourceTransactionManager
(
dataSource
);
...
@@ -272,6 +278,7 @@ public class EnableTransactionManagementIntegrationTests {
...
@@ -272,6 +278,7 @@ public class EnableTransactionManagementIntegrationTests {
@Configuration
@Configuration
@EnableTransactionManagement
@EnableTransactionManagement
static
class
NonConventionalTxManagerNameConfig
{
static
class
NonConventionalTxManagerNameConfig
{
@Bean
@Bean
PlatformTransactionManager
txManager
(
DataSource
dataSource
)
{
PlatformTransactionManager
txManager
(
DataSource
dataSource
)
{
return
new
DataSourceTransactionManager
(
dataSource
);
return
new
DataSourceTransactionManager
(
dataSource
);
...
@@ -282,6 +289,7 @@ public class EnableTransactionManagementIntegrationTests {
...
@@ -282,6 +289,7 @@ public class EnableTransactionManagementIntegrationTests {
@Configuration
@Configuration
@EnableTransactionManagement
(
proxyTargetClass
=
true
)
@EnableTransactionManagement
(
proxyTargetClass
=
true
)
static
class
ProxyTargetClassTxConfig
{
static
class
ProxyTargetClassTxConfig
{
@Bean
@Bean
PlatformTransactionManager
transactionManager
(
DataSource
dataSource
)
{
PlatformTransactionManager
transactionManager
(
DataSource
dataSource
)
{
return
new
DataSourceTransactionManager
(
dataSource
);
return
new
DataSourceTransactionManager
(
dataSource
);
...
@@ -292,6 +300,7 @@ public class EnableTransactionManagementIntegrationTests {
...
@@ -292,6 +300,7 @@ public class EnableTransactionManagementIntegrationTests {
@Configuration
@Configuration
@EnableTransactionManagement
(
mode
=
AdviceMode
.
ASPECTJ
)
@EnableTransactionManagement
(
mode
=
AdviceMode
.
ASPECTJ
)
static
class
AspectJTxConfig
{
static
class
AspectJTxConfig
{
@Bean
@Bean
PlatformTransactionManager
transactionManager
(
DataSource
dataSource
)
{
PlatformTransactionManager
transactionManager
(
DataSource
dataSource
)
{
return
new
DataSourceTransactionManager
(
dataSource
);
return
new
DataSourceTransactionManager
(
dataSource
);
...
@@ -301,6 +310,7 @@ public class EnableTransactionManagementIntegrationTests {
...
@@ -301,6 +310,7 @@ public class EnableTransactionManagementIntegrationTests {
@Configuration
@Configuration
static
class
Config
{
static
class
Config
{
@Bean
@Bean
FooRepository
fooRepository
()
{
FooRepository
fooRepository
()
{
JdbcFooRepository
repos
=
new
JdbcFooRepository
();
JdbcFooRepository
repos
=
new
JdbcFooRepository
();
...
@@ -318,6 +328,7 @@ public class EnableTransactionManagementIntegrationTests {
...
@@ -318,6 +328,7 @@ public class EnableTransactionManagementIntegrationTests {
interface
FooRepository
{
interface
FooRepository
{
List
<
Object
>
findAll
();
List
<
Object
>
findAll
();
}
}
...
@@ -335,6 +346,7 @@ public class EnableTransactionManagementIntegrationTests {
...
@@ -335,6 +346,7 @@ public class EnableTransactionManagementIntegrationTests {
}
}
}
}
@Repository
@Repository
static
class
DummyFooRepository
implements
FooRepository
{
static
class
DummyFooRepository
implements
FooRepository
{
...
@@ -344,4 +356,5 @@ public class EnableTransactionManagementIntegrationTests {
...
@@ -344,4 +356,5 @@ public class EnableTransactionManagementIntegrationTests {
return
Collections
.
emptyList
();
return
Collections
.
emptyList
();
}
}
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录