Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
342d760f
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,发现更多精彩内容 >>
提交
342d760f
编写于
12月 29, 2015
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing
(cherry picked from commit
27c2e8c8
)
上级
acecda71
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
72 addition
and
57 deletion
+72
-57
spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java
...amework/cache/annotation/SpringCacheAnnotationParser.java
+2
-2
spring-context/src/main/java/org/springframework/context/annotation/BeanAnnotationHelper.java
...ingframework/context/annotation/BeanAnnotationHelper.java
+6
-5
spring-context/src/test/java/org/springframework/context/annotation/ComponentScanAnnotationIntegrationTests.java
...t/annotation/ComponentScanAnnotationIntegrationTests.java
+39
-30
spring-context/src/test/java/org/springframework/context/annotation/ComponentScanAnnotationTests.java
...work/context/annotation/ComponentScanAnnotationTests.java
+3
-3
spring-context/src/test/java/org/springframework/context/annotation/ComponentScanParserBeanDefinitionDefaultsTests.java
...ation/ComponentScanParserBeanDefinitionDefaultsTests.java
+3
-4
spring-context/src/test/java/org/springframework/context/annotation/ComponentScanParserScopedProxyTests.java
...ntext/annotation/ComponentScanParserScopedProxyTests.java
+6
-0
spring-context/src/test/java/org/springframework/context/annotation/ComponentScanParserTests.java
...ramework/context/annotation/ComponentScanParserTests.java
+3
-3
spring-context/src/test/java/org/springframework/context/annotation/ComponentScanParserWithUserDefinedStrategiesTests.java
...on/ComponentScanParserWithUserDefinedStrategiesTests.java
+4
-4
spring-core/src/main/java/org/springframework/core/annotation/SynthesizedAnnotationInvocationHandler.java
...re/annotation/SynthesizedAnnotationInvocationHandler.java
+6
-6
未找到文件。
spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java
浏览文件 @
342d760f
...
...
@@ -195,7 +195,7 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
}
private
<
A
extends
Annotation
>
Collection
<
A
>
getAnnotations
(
AnnotatedElement
ae
,
Class
<
A
>
annotationType
)
{
Collection
<
A
>
anns
=
new
ArrayList
<
A
>(
2
);
Collection
<
A
>
anns
=
new
ArrayList
<
A
>(
1
);
// look at raw annotation
A
ann
=
ae
.
getAnnotation
(
annotationType
);
...
...
@@ -211,7 +211,7 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
}
}
return
(
anns
.
isEmpty
()
?
null
:
anns
);
return
(
!
anns
.
isEmpty
()
?
anns
:
null
);
}
/**
...
...
spring-context/src/main/java/org/springframework/context/annotation/BeanAnnotationHelper.java
浏览文件 @
342d760f
/*
* Copyright 2002-201
1
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.
...
...
@@ -29,17 +29,18 @@ import org.springframework.core.annotation.AnnotationUtils;
class
BeanAnnotationHelper
{
/**
* Return whether the given method is annotated directly or indirectly with @Bean.
* Return whether the given method is directly or indirectly annotated with
* the {@link Bean} annotation.
*/
public
static
boolean
isBeanAnnotated
(
Method
method
)
{
return
AnnotationUtils
.
findAnnotation
(
method
,
Bean
.
class
)
!=
null
;
return
(
AnnotationUtils
.
findAnnotation
(
method
,
Bean
.
class
)
!=
null
)
;
}
public
static
String
determineBeanNameFor
(
Method
beanMethod
)
{
//
by default
the bean name is the name of the @Bean-annotated method
//
By default,
the bean name is the name of the @Bean-annotated method
String
beanName
=
beanMethod
.
getName
();
//
check to see if the user has explicitly set the bean name
//
Check to see if the user has explicitly set a custom bean name...
Bean
bean
=
AnnotationUtils
.
findAnnotation
(
beanMethod
,
Bean
.
class
);
if
(
bean
!=
null
&&
bean
.
name
().
length
>
0
)
{
beanName
=
bean
.
name
()[
0
];
...
...
spring-context/src/test/java/org/springframework/context/annotation/ComponentScanAnnotationIntegrationTests.java
浏览文件 @
342d760f
...
...
@@ -147,7 +147,7 @@ public class ComponentScanAnnotationIntegrationTests {
@Test
public
void
withCustomBeanNameGenerator
()
{
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
();
ctx
.
register
(
ComponentScanWithBeanNameGene
ne
rator
.
class
);
ctx
.
register
(
ComponentScanWithBeanNameGenerator
.
class
);
ctx
.
refresh
();
assertThat
(
ctx
.
containsBean
(
"custom_fooServiceImpl"
),
is
(
true
));
assertThat
(
ctx
.
containsBean
(
"fooServiceImpl"
),
is
(
false
));
...
...
@@ -241,7 +241,8 @@ public class ComponentScanAnnotationIntegrationTests {
@ComponentScan
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Target
(
ElementType
.
TYPE
)
public
static
@interface
ComposedConfiguration
{
public
@interface
ComposedConfiguration
{
String
[]
basePackages
()
default
{};
}
...
...
@@ -253,8 +254,9 @@ public class ComponentScanAnnotationIntegrationTests {
@Configuration
@ComponentScan
(
basePackageClasses
=
example
.
scannable
.
_package
.
class
)
@ComponentScan
(
basePackageClasses
=
example
.
scannable
.
_package
.
class
)
class
ComponentScanAnnotatedConfig
{
@Bean
public
TestBean
testBean
()
{
return
new
TestBean
();
...
...
@@ -264,6 +266,7 @@ class ComponentScanAnnotatedConfig {
@Configuration
@ComponentScan
(
"example.scannable"
)
class
ComponentScanAnnotatedConfig_WithValueAttribute
{
@Bean
public
TestBean
testBean
()
{
return
new
TestBean
();
...
...
@@ -272,13 +275,16 @@ class ComponentScanAnnotatedConfig_WithValueAttribute {
@Configuration
@ComponentScan
class
ComponentScanWithNoPackagesConfig
{}
class
ComponentScanWithNoPackagesConfig
{
}
@Configuration
@ComponentScan
(
basePackages
=
"example.scannable"
,
nameGenerator
=
MyBeanNameGenerator
.
class
)
class
ComponentScanWithBeanNameGenenerator
{}
@ComponentScan
(
basePackages
=
"example.scannable"
,
nameGenerator
=
MyBeanNameGenerator
.
class
)
class
ComponentScanWithBeanNameGenerator
{
}
class
MyBeanNameGenerator
extends
AnnotationBeanNameGenerator
{
@Override
public
String
generateBeanName
(
BeanDefinition
definition
,
BeanDefinitionRegistry
registry
)
{
return
"custom_"
+
super
.
generateBeanName
(
definition
,
registry
);
...
...
@@ -286,10 +292,12 @@ class MyBeanNameGenerator extends AnnotationBeanNameGenerator {
}
@Configuration
@ComponentScan
(
basePackages
=
"example.scannable_scoped"
,
scopeResolver
=
MyScopeMetadataResolver
.
class
)
class
ComponentScanWithScopeResolver
{}
@ComponentScan
(
basePackages
=
"example.scannable_scoped"
,
scopeResolver
=
MyScopeMetadataResolver
.
class
)
class
ComponentScanWithScopeResolver
{
}
class
MyScopeMetadataResolver
extends
AnnotationScopeMetadataResolver
{
MyScopeMetadataResolver
()
{
this
.
scopeAnnotationType
=
MyScope
.
class
;
}
...
...
@@ -297,13 +305,14 @@ class MyScopeMetadataResolver extends AnnotationScopeMetadataResolver {
@Configuration
@ComponentScan
(
basePackages
=
"org.springframework.context.annotation"
,
useDefaultFilters
=
false
,
basePackages
=
"org.springframework.context.annotation"
,
useDefaultFilters
=
false
,
includeFilters
=
@Filter
(
type
=
FilterType
.
CUSTOM
,
classes
=
ComponentScanParserTests
.
CustomTypeFilter
.
class
),
// exclude this class from scanning since it's in the scanned package
excludeFilters
=
@Filter
(
type
=
FilterType
.
ASSIGNABLE_TYPE
,
classes
=
ComponentScanWithCustomTypeFilter
.
class
),
lazyInit
=
true
)
class
ComponentScanWithCustomTypeFilter
{
@Bean
@SuppressWarnings
({
"rawtypes"
,
"serial"
,
"unchecked"
})
public
static
CustomAutowireConfigurer
customAutowireConfigurer
()
{
...
...
@@ -318,30 +327,30 @@ class ComponentScanWithCustomTypeFilter {
}
@Configuration
@ComponentScan
(
basePackages
=
"example.scannable"
,
scopedProxy
=
ScopedProxyMode
.
INTERFACES
,
useDefaultFilters
=
false
,
@ComponentScan
(
basePackages
=
"example.scannable"
,
scopedProxy
=
ScopedProxyMode
.
INTERFACES
,
useDefaultFilters
=
false
,
includeFilters
=
@Filter
(
type
=
FilterType
.
ASSIGNABLE_TYPE
,
classes
=
ScopedProxyTestBean
.
class
))
class
ComponentScanWithScopedProxy
{}
@Configuration
@ComponentScan
(
basePackages
=
"example.scannable"
,
scopedProxy
=
ScopedProxyMode
.
INTERFACES
,
useDefaultFilters
=
false
,
includeFilters
=
@Filter
(
type
=
FilterType
.
REGEX
,
pattern
=
"((?:[a-z.]+))ScopedProxyTestBean"
))
@ComponentScan
(
basePackages
=
"example.scannable"
,
scopedProxy
=
ScopedProxyMode
.
INTERFACES
,
useDefaultFilters
=
false
,
includeFilters
=
@Filter
(
type
=
FilterType
.
REGEX
,
pattern
=
"((?:[a-z.]+))ScopedProxyTestBean"
))
class
ComponentScanWithScopedProxyThroughRegex
{}
@Configuration
@ComponentScan
(
basePackages
=
"example.scannable"
,
scopedProxy
=
ScopedProxyMode
.
INTERFACES
,
useDefaultFilters
=
false
,
includeFilters
=
@Filter
(
type
=
FilterType
.
ASPECTJ
,
pattern
=
"*..ScopedProxyTestBean"
))
@ComponentScan
(
basePackages
=
"example.scannable"
,
scopedProxy
=
ScopedProxyMode
.
INTERFACES
,
useDefaultFilters
=
false
,
includeFilters
=
@Filter
(
type
=
FilterType
.
ASPECTJ
,
pattern
=
"*..ScopedProxyTestBean"
))
class
ComponentScanWithScopedProxyThroughAspectJPattern
{}
@Configuration
@ComponentScan
(
basePackages
=
"example.scannable"
,
useDefaultFilters
=
false
,
includeFilters
=
{
@ComponentScan
(
basePackages
=
"example.scannable"
,
useDefaultFilters
=
false
,
includeFilters
=
{
@Filter
(
CustomStereotype
.
class
),
@Filter
(
CustomComponent
.
class
)
}
...
...
@@ -349,15 +358,15 @@ class ComponentScanWithScopedProxyThroughAspectJPattern {}
class
ComponentScanWithMultipleAnnotationIncludeFilters1
{}
@Configuration
@ComponentScan
(
basePackages
=
"example.scannable"
,
useDefaultFilters
=
false
,
includeFilters
=
@Filter
({
CustomStereotype
.
class
,
CustomComponent
.
class
})
@ComponentScan
(
basePackages
=
"example.scannable"
,
useDefaultFilters
=
false
,
includeFilters
=
@Filter
({
CustomStereotype
.
class
,
CustomComponent
.
class
})
)
class
ComponentScanWithMultipleAnnotationIncludeFilters2
{}
@Configuration
@ComponentScan
(
value
=
"example.scannable"
,
basePackages
=
"example.scannable"
,
basePackageClasses
=
example
.
scannable
.
_package
.
class
)
value
=
"example.scannable"
,
basePackages
=
"example.scannable"
,
basePackageClasses
=
example
.
scannable
.
_package
.
class
)
class
ComponentScanWithBasePackagesAndValueAlias
{}
spring-context/src/test/java/org/springframework/context/annotation/ComponentScanAnnotationTests.java
浏览文件 @
342d760f
/*
* 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.
...
...
@@ -44,7 +44,7 @@ public class ComponentScanAnnotationTests {
@Configuration
@ComponentScan
(
basePackageClasses
={
TestBean
.
class
}
,
basePackageClasses
=
TestBean
.
class
,
nameGenerator
=
DefaultBeanNameGenerator
.
class
,
scopedProxy
=
ScopedProxyMode
.
NO
,
scopeResolver
=
AnnotationScopeMetadataResolver
.
class
,
...
...
@@ -61,6 +61,6 @@ public class ComponentScanAnnotationTests {
class
MyConfig
{
}
@ComponentScan
(
basePackageClasses
=
example
.
scannable
.
NamedComponent
.
class
)
@ComponentScan
(
basePackageClasses
=
example
.
scannable
.
NamedComponent
.
class
)
class
SimpleConfig
{
}
spring-context/src/test/java/org/springframework/context/annotation/ComponentScanParserBeanDefinitionDefaultsTests.java
浏览文件 @
342d760f
/*
* Copyright 2002-201
3
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.
...
...
@@ -122,7 +122,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
context
.
refresh
();
fail
(
"expected exception due to multiple matches for byType autowiring"
);
}
catch
(
UnsatisfiedDependencyException
e
)
{
catch
(
UnsatisfiedDependencyException
e
x
)
{
// expected
}
}
...
...
@@ -161,7 +161,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
context
.
refresh
();
fail
(
"expected exception due to dependency check"
);
}
catch
(
UnsatisfiedDependencyException
e
)
{
catch
(
UnsatisfiedDependencyException
e
x
)
{
// expected
}
}
...
...
@@ -230,7 +230,6 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
private
boolean
destroyed
;
public
DefaultsTestBean
()
{
INIT_COUNT
++;
}
...
...
spring-context/src/test/java/org/springframework/context/annotation/ComponentScanParserScopedProxyTests.java
浏览文件 @
342d760f
...
...
@@ -42,11 +42,13 @@ public class ComponentScanParserScopedProxyTests {
@Rule
public
final
ExpectedException
exception
=
ExpectedException
.
none
();
@Test
public
void
testDefaultScopedProxy
()
{
ClassPathXmlApplicationContext
context
=
new
ClassPathXmlApplicationContext
(
"org/springframework/context/annotation/scopedProxyDefaultTests.xml"
);
context
.
getBeanFactory
().
registerScope
(
"myScope"
,
new
SimpleMapScope
());
ScopedProxyTestBean
bean
=
(
ScopedProxyTestBean
)
context
.
getBean
(
"scopedProxyTestBean"
);
// should not be a proxy
assertFalse
(
AopUtils
.
isAopProxy
(
bean
));
...
...
@@ -58,6 +60,7 @@ public class ComponentScanParserScopedProxyTests {
ClassPathXmlApplicationContext
context
=
new
ClassPathXmlApplicationContext
(
"org/springframework/context/annotation/scopedProxyNoTests.xml"
);
context
.
getBeanFactory
().
registerScope
(
"myScope"
,
new
SimpleMapScope
());
ScopedProxyTestBean
bean
=
(
ScopedProxyTestBean
)
context
.
getBean
(
"scopedProxyTestBean"
);
// should not be a proxy
assertFalse
(
AopUtils
.
isAopProxy
(
bean
));
...
...
@@ -69,6 +72,7 @@ public class ComponentScanParserScopedProxyTests {
ClassPathXmlApplicationContext
context
=
new
ClassPathXmlApplicationContext
(
"org/springframework/context/annotation/scopedProxyInterfacesTests.xml"
);
context
.
getBeanFactory
().
registerScope
(
"myScope"
,
new
SimpleMapScope
());
// should cast to the interface
FooService
bean
=
(
FooService
)
context
.
getBean
(
"scopedProxyTestBean"
);
// should be dynamic proxy
...
...
@@ -86,6 +90,7 @@ public class ComponentScanParserScopedProxyTests {
ClassPathXmlApplicationContext
context
=
new
ClassPathXmlApplicationContext
(
"org/springframework/context/annotation/scopedProxyTargetClassTests.xml"
);
context
.
getBeanFactory
().
registerScope
(
"myScope"
,
new
SimpleMapScope
());
ScopedProxyTestBean
bean
=
(
ScopedProxyTestBean
)
context
.
getBean
(
"scopedProxyTestBean"
);
// should be a class-based proxy
assertTrue
(
AopUtils
.
isCglibProxy
(
bean
));
...
...
@@ -103,6 +108,7 @@ public class ComponentScanParserScopedProxyTests {
exception
.
expect
(
BeanDefinitionParsingException
.
class
);
exception
.
expectMessage
(
containsString
(
"Cannot define both 'scope-resolver' and 'scoped-proxy' on <component-scan> tag"
));
exception
.
expectMessage
(
containsString
(
"Offending resource: class path resource [org/springframework/context/annotation/scopedProxyInvalidConfigTests.xml]"
));
new
ClassPathXmlApplicationContext
(
"org/springframework/context/annotation/scopedProxyInvalidConfigTests.xml"
);
}
...
...
spring-context/src/test/java/org/springframework/context/annotation/ComponentScanParserTests.java
浏览文件 @
342d760f
/*
* 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.
...
...
@@ -145,9 +145,9 @@ public class ComponentScanParserTests {
}
@Target
({
ElementType
.
TYPE
,
ElementType
.
FIELD
})
@Target
({
ElementType
.
TYPE
,
ElementType
.
FIELD
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
static
@interface
CustomAnnotation
{
public
@interface
CustomAnnotation
{
}
...
...
spring-context/src/test/java/org/springframework/context/annotation/ComponentScanParserWithUserDefinedStrategiesTests.java
浏览文件 @
342d760f
/*
* Copyright 2002-201
2
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.
...
...
@@ -53,7 +53,7 @@ public class ComponentScanParserWithUserDefinedStrategiesTests {
"org/springframework/context/annotation/invalidConstructorNameGeneratorTests.xml"
);
fail
(
"should have failed: no-arg constructor is required"
);
}
catch
(
BeansException
e
)
{
catch
(
BeansException
e
x
)
{
// expected
}
}
...
...
@@ -65,7 +65,7 @@ public class ComponentScanParserWithUserDefinedStrategiesTests {
"org/springframework/context/annotation/invalidClassNameScopeResolverTests.xml"
);
fail
(
"should have failed: no such class"
);
}
catch
(
BeansException
e
)
{
catch
(
BeansException
e
x
)
{
// expected
}
}
...
...
spring-core/src/main/java/org/springframework/core/annotation/SynthesizedAnnotationInvocationHandler.java
浏览文件 @
342d760f
...
...
@@ -60,6 +60,7 @@ class SynthesizedAnnotationInvocationHandler implements InvocationHandler {
this
.
attributeExtractor
=
attributeExtractor
;
}
@Override
public
Object
invoke
(
Object
proxy
,
Method
method
,
Object
[]
args
)
throws
Throwable
{
if
(
isEqualsMethod
(
method
))
{
...
...
@@ -75,8 +76,8 @@ class SynthesizedAnnotationInvocationHandler implements InvocationHandler {
return
annotationType
();
}
if
(!
isAttributeMethod
(
method
))
{
String
msg
=
String
.
format
(
"Method [%s] is unsupported for synthesized annotation type [%s]"
,
method
,
annotationType
());
String
msg
=
String
.
format
(
"Method [%s] is unsupported for synthesized annotation type [%s]"
,
method
,
annotationType
());
throw
new
AnnotationConfigurationException
(
msg
);
}
return
getAttributeValue
(
method
);
...
...
@@ -92,9 +93,9 @@ class SynthesizedAnnotationInvocationHandler implements InvocationHandler {
if
(
value
==
null
)
{
value
=
this
.
attributeExtractor
.
getAttributeValue
(
attributeMethod
);
if
(
value
==
null
)
{
throw
new
IllegalStateException
(
String
.
format
(
"%s returned null for attribute name [%s] from attribute source [%s]"
,
this
.
attributeExtractor
.
getClass
().
getName
(),
attributeName
,
this
.
attributeExtractor
.
getSource
())
);
String
msg
=
String
.
format
(
"%s returned null for attribute name [%s] from attribute source [%s]"
,
this
.
attributeExtractor
.
getClass
().
getName
(),
attributeName
,
this
.
attributeExtractor
.
getSource
());
throw
new
IllegalStateException
(
msg
);
}
// Synthesize nested annotations before returning them.
...
...
@@ -200,7 +201,6 @@ class SynthesizedAnnotationInvocationHandler implements InvocationHandler {
* in Spring's {@link ObjectUtils} because those hash code generation
* algorithms do not comply with the requirements specified in
* {@link Annotation#hashCode()}.
*
* @param array the array to compute the hash code for
*/
private
int
hashCodeForArray
(
Object
array
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录