Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
a7ec6dc0
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,发现更多精彩内容 >>
提交
a7ec6dc0
编写于
12月 09, 2016
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ImportRegistry properly tracks excluded superclasses
Issue: SPR-14972
上级
e1b89c7f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
81 addition
and
21 deletion
+81
-21
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java
...xt/annotation/ConfigurationClassBeanDefinitionReader.java
+1
-1
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java
...ramework/context/annotation/ConfigurationClassParser.java
+9
-8
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationCondition.java
...gframework/context/annotation/ConfigurationCondition.java
+2
-2
spring-context/src/main/java/org/springframework/context/annotation/ImportRegistry.java
...rg/springframework/context/annotation/ImportRegistry.java
+2
-2
spring-tx/src/test/java/org/springframework/transaction/annotation/EnableTransactionManagementTests.java
...nsaction/annotation/EnableTransactionManagementTests.java
+67
-8
未找到文件。
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java
浏览文件 @
a7ec6dc0
...
...
@@ -129,7 +129,7 @@ class ConfigurationClassBeanDefinitionReader {
if
(
StringUtils
.
hasLength
(
beanName
)
&&
this
.
registry
.
containsBeanDefinition
(
beanName
))
{
this
.
registry
.
removeBeanDefinition
(
beanName
);
}
this
.
importRegistry
.
removeImportingClass
For
(
configClass
.
getMetadata
().
getClassName
());
this
.
importRegistry
.
removeImportingClass
(
configClass
.
getMetadata
().
getClassName
());
return
;
}
...
...
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java
浏览文件 @
a7ec6dc0
...
...
@@ -644,22 +644,23 @@ class ConfigurationClassParser {
}
@Override
public
void
removeImportingClassFor
(
String
importedClass
)
{
public
AnnotationMetadata
getImportingClassFor
(
String
importedClass
)
{
List
<
AnnotationMetadata
>
list
=
this
.
imports
.
get
(
importedClass
);
return
(!
CollectionUtils
.
isEmpty
(
list
)
?
list
.
get
(
list
.
size
()
-
1
)
:
null
);
}
@Override
public
void
removeImportingClass
(
String
importingClass
)
{
for
(
List
<
AnnotationMetadata
>
list
:
this
.
imports
.
values
())
{
for
(
Iterator
<
AnnotationMetadata
>
iterator
=
list
.
iterator
();
iterator
.
hasNext
();)
{
if
(
iterator
.
next
().
getClassName
().
equals
(
import
ed
Class
))
{
if
(
iterator
.
next
().
getClassName
().
equals
(
import
ing
Class
))
{
iterator
.
remove
();
break
;
}
}
}
}
@Override
public
AnnotationMetadata
getImportingClassFor
(
String
importedClass
)
{
List
<
AnnotationMetadata
>
list
=
this
.
imports
.
get
(
importedClass
);
return
(!
CollectionUtils
.
isEmpty
(
list
)
?
list
.
get
(
list
.
size
()
-
1
)
:
null
);
}
/**
* Given a stack containing (in order)
* <ul>
...
...
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationCondition.java
浏览文件 @
a7ec6dc0
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -38,7 +38,7 @@ public interface ConfigurationCondition extends Condition {
/**
* The various configuration phases where the condition could be evaluated.
*/
public
static
enum
ConfigurationPhase
{
enum
ConfigurationPhase
{
/**
* The {@link Condition} should be evaluated as a {@code @Configuration}
...
...
spring-context/src/main/java/org/springframework/context/annotation/ImportRegistry.java
浏览文件 @
a7ec6dc0
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -26,6 +26,6 @@ interface ImportRegistry {
AnnotationMetadata
getImportingClassFor
(
String
importedClass
);
void
removeImportingClass
For
(
String
imported
Class
);
void
removeImportingClass
(
String
importing
Class
);
}
spring-tx/src/test/java/org/springframework/transaction/annotation/EnableTransactionManagementTests.java
浏览文件 @
a7ec6dc0
...
...
@@ -26,7 +26,11 @@ import org.springframework.context.ConfigurableApplicationContext;
import
org.springframework.context.annotation.AdviceMode
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ConditionContext
;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.ConfigurationCondition
;
import
org.springframework.core.type.AnnotatedTypeMetadata
;
import
org.springframework.stereotype.Service
;
import
org.springframework.tests.transaction.CallCountingTransactionManager
;
import
org.springframework.transaction.PlatformTransactionManager
;
...
...
@@ -49,7 +53,8 @@ public class EnableTransactionManagementTests {
@Test
public
void
transactionProxyIsCreated
()
{
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
(
EnableTxConfig
.
class
,
TxManagerConfig
.
class
);
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
(
EnableTxConfig
.
class
,
TxManagerConfig
.
class
);
TransactionalTestBean
bean
=
ctx
.
getBean
(
TransactionalTestBean
.
class
);
assertTrue
(
"testBean is not a proxy"
,
AopUtils
.
isAopProxy
(
bean
));
Map
<?,?>
services
=
ctx
.
getBeansWithAnnotation
(
Service
.
class
);
...
...
@@ -59,7 +64,19 @@ public class EnableTransactionManagementTests {
@Test
public
void
transactionProxyIsCreatedWithEnableOnSuperclass
()
{
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
(
InheritedEnableTxConfig
.
class
,
TxManagerConfig
.
class
);
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
(
InheritedEnableTxConfig
.
class
,
TxManagerConfig
.
class
);
TransactionalTestBean
bean
=
ctx
.
getBean
(
TransactionalTestBean
.
class
);
assertTrue
(
"testBean is not a proxy"
,
AopUtils
.
isAopProxy
(
bean
));
Map
<?,?>
services
=
ctx
.
getBeansWithAnnotation
(
Service
.
class
);
assertTrue
(
"Stereotype annotation not visible"
,
services
.
containsKey
(
"testBean"
));
ctx
.
close
();
}
@Test
public
void
transactionProxyIsCreatedWithEnableOnExcludedSuperclass
()
{
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
(
ParentEnableTxConfig
.
class
,
ChildEnableTxConfig
.
class
,
TxManagerConfig
.
class
);
TransactionalTestBean
bean
=
ctx
.
getBean
(
TransactionalTestBean
.
class
);
assertTrue
(
"testBean is not a proxy"
,
AopUtils
.
isAopProxy
(
bean
));
Map
<?,?>
services
=
ctx
.
getBeansWithAnnotation
(
Service
.
class
);
...
...
@@ -69,7 +86,8 @@ public class EnableTransactionManagementTests {
@Test
public
void
txManagerIsResolvedOnInvocationOfTransactionalMethod
()
{
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
(
EnableTxConfig
.
class
,
TxManagerConfig
.
class
);
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.
...
...
@@ -79,7 +97,8 @@ public class EnableTransactionManagementTests {
@Test
public
void
txManagerIsResolvedCorrectlyWhenMultipleManagersArePresent
()
{
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
(
EnableTxConfig
.
class
,
MultiTxManagerConfig
.
class
);
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.
...
...
@@ -95,7 +114,7 @@ public class EnableTransactionManagementTests {
@SuppressWarnings
(
"resource"
)
public
void
proxyTypeAspectJCausesRegistrationOfAnnotationTransactionAspect
()
{
try
{
new
AnnotationConfigApplicationContext
(
EnableAspect
J
TxConfig
.
class
,
TxManagerConfig
.
class
);
new
AnnotationConfigApplicationContext
(
EnableAspect
j
TxConfig
.
class
,
TxManagerConfig
.
class
);
fail
(
"should have thrown CNFE when trying to load AnnotationTransactionAspect. "
+
"Do you actually have org.springframework.aspects on the classpath?"
);
}
...
...
@@ -137,15 +156,54 @@ public class EnableTransactionManagementTests {
static
class
EnableTxConfig
{
}
@Configuration
static
class
InheritedEnableTxConfig
extends
EnableTxConfig
{
}
@Configuration
@EnableTransactionManagement
@Conditional
(
NeverCondition
.
class
)
static
class
ParentEnableTxConfig
{
@Bean
Object
someBean
()
{
return
new
Object
();
}
}
@Configuration
static
class
ChildEnableTxConfig
extends
ParentEnableTxConfig
{
@Override
Object
someBean
()
{
return
"X"
;
}
}
private
static
class
NeverCondition
implements
ConfigurationCondition
{
@Override
public
boolean
matches
(
ConditionContext
context
,
AnnotatedTypeMetadata
metadata
)
{
return
false
;
}
@Override
public
ConfigurationPhase
getConfigurationPhase
()
{
return
ConfigurationPhase
.
REGISTER_BEAN
;
}
}
@Configuration
@EnableTransactionManagement
(
mode
=
AdviceMode
.
ASPECTJ
)
static
class
EnableAspect
J
TxConfig
{
@EnableTransactionManagement
(
mode
=
AdviceMode
.
ASPECTJ
)
static
class
EnableAspect
j
TxConfig
{
}
@Configuration
@EnableTransactionManagement
static
class
Spr11915Config
{
...
...
@@ -162,6 +220,7 @@ public class EnableTransactionManagementTests {
}
}
@Configuration
static
class
TxManagerConfig
{
...
...
@@ -174,9 +233,9 @@ public class EnableTransactionManagementTests {
public
PlatformTransactionManager
txManager
()
{
return
new
CallCountingTransactionManager
();
}
}
@Configuration
static
class
MultiTxManagerConfig
extends
TxManagerConfig
implements
TransactionManagementConfigurer
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录