@@ -195,7 +195,7 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
|
|||||||
}
|
}
|
||||||
|
|
||||||
private <A extends Annotation> Collection<A> getAnnotations(AnnotatedElement ae, Class<A> annotationType) {
|
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
|
// look at raw annotation
|
||||||
A ann = ae.getAnnotation(annotationType);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2011 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
@@ -29,17 +29,18 @@ import org.springframework.core.annotation.AnnotationUtils;
|
|||||||
class BeanAnnotationHelper {
|
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) {
|
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) {
|
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();
|
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);
|
Bean bean = AnnotationUtils.findAnnotation(beanMethod, Bean.class);
|
||||||
if (bean != null && bean.name().length > 0) {
|
if (bean != null && bean.name().length > 0) {
|
||||||
beanName = bean.name()[0];
|
beanName = bean.name()[0];
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ public class ComponentScanAnnotationIntegrationTests {
|
|||||||
@Test
|
@Test
|
||||||
public void withCustomBeanNameGenerator() {
|
public void withCustomBeanNameGenerator() {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||||
ctx.register(ComponentScanWithBeanNameGenenerator.class);
|
ctx.register(ComponentScanWithBeanNameGenerator.class);
|
||||||
ctx.refresh();
|
ctx.refresh();
|
||||||
assertThat(ctx.containsBean("custom_fooServiceImpl"), is(true));
|
assertThat(ctx.containsBean("custom_fooServiceImpl"), is(true));
|
||||||
assertThat(ctx.containsBean("fooServiceImpl"), is(false));
|
assertThat(ctx.containsBean("fooServiceImpl"), is(false));
|
||||||
@@ -241,7 +241,8 @@ public class ComponentScanAnnotationIntegrationTests {
|
|||||||
@ComponentScan
|
@ComponentScan
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.TYPE)
|
@Target(ElementType.TYPE)
|
||||||
public static @interface ComposedConfiguration {
|
public @interface ComposedConfiguration {
|
||||||
|
|
||||||
String[] basePackages() default {};
|
String[] basePackages() default {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,8 +254,9 @@ public class ComponentScanAnnotationIntegrationTests {
|
|||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan(basePackageClasses=example.scannable._package.class)
|
@ComponentScan(basePackageClasses = example.scannable._package.class)
|
||||||
class ComponentScanAnnotatedConfig {
|
class ComponentScanAnnotatedConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public TestBean testBean() {
|
public TestBean testBean() {
|
||||||
return new TestBean();
|
return new TestBean();
|
||||||
@@ -264,6 +266,7 @@ class ComponentScanAnnotatedConfig {
|
|||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan("example.scannable")
|
@ComponentScan("example.scannable")
|
||||||
class ComponentScanAnnotatedConfig_WithValueAttribute {
|
class ComponentScanAnnotatedConfig_WithValueAttribute {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public TestBean testBean() {
|
public TestBean testBean() {
|
||||||
return new TestBean();
|
return new TestBean();
|
||||||
@@ -272,13 +275,16 @@ class ComponentScanAnnotatedConfig_WithValueAttribute {
|
|||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan
|
@ComponentScan
|
||||||
class ComponentScanWithNoPackagesConfig {}
|
class ComponentScanWithNoPackagesConfig {
|
||||||
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan(basePackages="example.scannable", nameGenerator=MyBeanNameGenerator.class)
|
@ComponentScan(basePackages = "example.scannable", nameGenerator = MyBeanNameGenerator.class)
|
||||||
class ComponentScanWithBeanNameGenenerator {}
|
class ComponentScanWithBeanNameGenerator {
|
||||||
|
}
|
||||||
|
|
||||||
class MyBeanNameGenerator extends AnnotationBeanNameGenerator {
|
class MyBeanNameGenerator extends AnnotationBeanNameGenerator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
|
public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
|
||||||
return "custom_" + super.generateBeanName(definition, registry);
|
return "custom_" + super.generateBeanName(definition, registry);
|
||||||
@@ -286,10 +292,12 @@ class MyBeanNameGenerator extends AnnotationBeanNameGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan(basePackages="example.scannable_scoped", scopeResolver=MyScopeMetadataResolver.class)
|
@ComponentScan(basePackages = "example.scannable_scoped", scopeResolver = MyScopeMetadataResolver.class)
|
||||||
class ComponentScanWithScopeResolver {}
|
class ComponentScanWithScopeResolver {
|
||||||
|
}
|
||||||
|
|
||||||
class MyScopeMetadataResolver extends AnnotationScopeMetadataResolver {
|
class MyScopeMetadataResolver extends AnnotationScopeMetadataResolver {
|
||||||
|
|
||||||
MyScopeMetadataResolver() {
|
MyScopeMetadataResolver() {
|
||||||
this.scopeAnnotationType = MyScope.class;
|
this.scopeAnnotationType = MyScope.class;
|
||||||
}
|
}
|
||||||
@@ -297,13 +305,14 @@ class MyScopeMetadataResolver extends AnnotationScopeMetadataResolver {
|
|||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan(
|
@ComponentScan(
|
||||||
basePackages="org.springframework.context.annotation",
|
basePackages = "org.springframework.context.annotation",
|
||||||
useDefaultFilters=false,
|
useDefaultFilters = false,
|
||||||
includeFilters = @Filter(type = FilterType.CUSTOM, classes = ComponentScanParserTests.CustomTypeFilter.class),
|
includeFilters = @Filter(type = FilterType.CUSTOM, classes = ComponentScanParserTests.CustomTypeFilter.class),
|
||||||
// exclude this class from scanning since it's in the scanned package
|
// exclude this class from scanning since it's in the scanned package
|
||||||
excludeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = ComponentScanWithCustomTypeFilter.class),
|
excludeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = ComponentScanWithCustomTypeFilter.class),
|
||||||
lazyInit = true)
|
lazyInit = true)
|
||||||
class ComponentScanWithCustomTypeFilter {
|
class ComponentScanWithCustomTypeFilter {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@SuppressWarnings({ "rawtypes", "serial", "unchecked" })
|
@SuppressWarnings({ "rawtypes", "serial", "unchecked" })
|
||||||
public static CustomAutowireConfigurer customAutowireConfigurer() {
|
public static CustomAutowireConfigurer customAutowireConfigurer() {
|
||||||
@@ -318,30 +327,30 @@ class ComponentScanWithCustomTypeFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan(basePackages="example.scannable",
|
@ComponentScan(basePackages = "example.scannable",
|
||||||
scopedProxy=ScopedProxyMode.INTERFACES,
|
scopedProxy = ScopedProxyMode.INTERFACES,
|
||||||
useDefaultFilters=false,
|
useDefaultFilters = false,
|
||||||
includeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = ScopedProxyTestBean.class))
|
includeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = ScopedProxyTestBean.class))
|
||||||
class ComponentScanWithScopedProxy {}
|
class ComponentScanWithScopedProxy {}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan(basePackages="example.scannable",
|
@ComponentScan(basePackages = "example.scannable",
|
||||||
scopedProxy=ScopedProxyMode.INTERFACES,
|
scopedProxy = ScopedProxyMode.INTERFACES,
|
||||||
useDefaultFilters=false,
|
useDefaultFilters = false,
|
||||||
includeFilters=@Filter(type=FilterType.REGEX, pattern ="((?:[a-z.]+))ScopedProxyTestBean"))
|
includeFilters = @Filter(type=FilterType.REGEX, pattern = "((?:[a-z.]+))ScopedProxyTestBean"))
|
||||||
class ComponentScanWithScopedProxyThroughRegex {}
|
class ComponentScanWithScopedProxyThroughRegex {}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan(basePackages="example.scannable",
|
@ComponentScan(basePackages = "example.scannable",
|
||||||
scopedProxy=ScopedProxyMode.INTERFACES,
|
scopedProxy = ScopedProxyMode.INTERFACES,
|
||||||
useDefaultFilters=false,
|
useDefaultFilters = false,
|
||||||
includeFilters=@Filter(type=FilterType.ASPECTJ, pattern ="*..ScopedProxyTestBean"))
|
includeFilters = @Filter(type=FilterType.ASPECTJ, pattern = "*..ScopedProxyTestBean"))
|
||||||
class ComponentScanWithScopedProxyThroughAspectJPattern {}
|
class ComponentScanWithScopedProxyThroughAspectJPattern {}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan(basePackages="example.scannable",
|
@ComponentScan(basePackages = "example.scannable",
|
||||||
useDefaultFilters=false,
|
useDefaultFilters = false,
|
||||||
includeFilters={
|
includeFilters = {
|
||||||
@Filter(CustomStereotype.class),
|
@Filter(CustomStereotype.class),
|
||||||
@Filter(CustomComponent.class)
|
@Filter(CustomComponent.class)
|
||||||
}
|
}
|
||||||
@@ -349,15 +358,15 @@ class ComponentScanWithScopedProxyThroughAspectJPattern {}
|
|||||||
class ComponentScanWithMultipleAnnotationIncludeFilters1 {}
|
class ComponentScanWithMultipleAnnotationIncludeFilters1 {}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan(basePackages="example.scannable",
|
@ComponentScan(basePackages = "example.scannable",
|
||||||
useDefaultFilters=false,
|
useDefaultFilters = false,
|
||||||
includeFilters=@Filter({CustomStereotype.class, CustomComponent.class})
|
includeFilters = @Filter({CustomStereotype.class, CustomComponent.class})
|
||||||
)
|
)
|
||||||
class ComponentScanWithMultipleAnnotationIncludeFilters2 {}
|
class ComponentScanWithMultipleAnnotationIncludeFilters2 {}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan(
|
@ComponentScan(
|
||||||
value="example.scannable",
|
value = "example.scannable",
|
||||||
basePackages="example.scannable",
|
basePackages = "example.scannable",
|
||||||
basePackageClasses=example.scannable._package.class)
|
basePackageClasses = example.scannable._package.class)
|
||||||
class ComponentScanWithBasePackagesAndValueAlias {}
|
class ComponentScanWithBasePackagesAndValueAlias {}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
@@ -44,7 +44,7 @@ public class ComponentScanAnnotationTests {
|
|||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan(
|
@ComponentScan(
|
||||||
basePackageClasses={TestBean.class},
|
basePackageClasses = TestBean.class,
|
||||||
nameGenerator = DefaultBeanNameGenerator.class,
|
nameGenerator = DefaultBeanNameGenerator.class,
|
||||||
scopedProxy = ScopedProxyMode.NO,
|
scopedProxy = ScopedProxyMode.NO,
|
||||||
scopeResolver = AnnotationScopeMetadataResolver.class,
|
scopeResolver = AnnotationScopeMetadataResolver.class,
|
||||||
@@ -61,6 +61,6 @@ public class ComponentScanAnnotationTests {
|
|||||||
class MyConfig {
|
class MyConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ComponentScan(basePackageClasses=example.scannable.NamedComponent.class)
|
@ComponentScan(basePackageClasses = example.scannable.NamedComponent.class)
|
||||||
class SimpleConfig {
|
class SimpleConfig {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
@@ -122,7 +122,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
|
|||||||
context.refresh();
|
context.refresh();
|
||||||
fail("expected exception due to multiple matches for byType autowiring");
|
fail("expected exception due to multiple matches for byType autowiring");
|
||||||
}
|
}
|
||||||
catch (UnsatisfiedDependencyException e) {
|
catch (UnsatisfiedDependencyException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,7 +161,7 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
|
|||||||
context.refresh();
|
context.refresh();
|
||||||
fail("expected exception due to dependency check");
|
fail("expected exception due to dependency check");
|
||||||
}
|
}
|
||||||
catch (UnsatisfiedDependencyException e) {
|
catch (UnsatisfiedDependencyException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -230,7 +230,6 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
|
|||||||
|
|
||||||
private boolean destroyed;
|
private boolean destroyed;
|
||||||
|
|
||||||
|
|
||||||
public DefaultsTestBean() {
|
public DefaultsTestBean() {
|
||||||
INIT_COUNT++;
|
INIT_COUNT++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,11 +42,13 @@ public class ComponentScanParserScopedProxyTests {
|
|||||||
@Rule
|
@Rule
|
||||||
public final ExpectedException exception = ExpectedException.none();
|
public final ExpectedException exception = ExpectedException.none();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultScopedProxy() {
|
public void testDefaultScopedProxy() {
|
||||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||||
"org/springframework/context/annotation/scopedProxyDefaultTests.xml");
|
"org/springframework/context/annotation/scopedProxyDefaultTests.xml");
|
||||||
context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
|
context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
|
||||||
|
|
||||||
ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean");
|
ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean");
|
||||||
// should not be a proxy
|
// should not be a proxy
|
||||||
assertFalse(AopUtils.isAopProxy(bean));
|
assertFalse(AopUtils.isAopProxy(bean));
|
||||||
@@ -58,6 +60,7 @@ public class ComponentScanParserScopedProxyTests {
|
|||||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||||
"org/springframework/context/annotation/scopedProxyNoTests.xml");
|
"org/springframework/context/annotation/scopedProxyNoTests.xml");
|
||||||
context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
|
context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
|
||||||
|
|
||||||
ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean");
|
ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean");
|
||||||
// should not be a proxy
|
// should not be a proxy
|
||||||
assertFalse(AopUtils.isAopProxy(bean));
|
assertFalse(AopUtils.isAopProxy(bean));
|
||||||
@@ -69,6 +72,7 @@ public class ComponentScanParserScopedProxyTests {
|
|||||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||||
"org/springframework/context/annotation/scopedProxyInterfacesTests.xml");
|
"org/springframework/context/annotation/scopedProxyInterfacesTests.xml");
|
||||||
context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
|
context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
|
||||||
|
|
||||||
// should cast to the interface
|
// should cast to the interface
|
||||||
FooService bean = (FooService) context.getBean("scopedProxyTestBean");
|
FooService bean = (FooService) context.getBean("scopedProxyTestBean");
|
||||||
// should be dynamic proxy
|
// should be dynamic proxy
|
||||||
@@ -86,6 +90,7 @@ public class ComponentScanParserScopedProxyTests {
|
|||||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||||
"org/springframework/context/annotation/scopedProxyTargetClassTests.xml");
|
"org/springframework/context/annotation/scopedProxyTargetClassTests.xml");
|
||||||
context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
|
context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
|
||||||
|
|
||||||
ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean");
|
ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean");
|
||||||
// should be a class-based proxy
|
// should be a class-based proxy
|
||||||
assertTrue(AopUtils.isCglibProxy(bean));
|
assertTrue(AopUtils.isCglibProxy(bean));
|
||||||
@@ -103,6 +108,7 @@ public class ComponentScanParserScopedProxyTests {
|
|||||||
exception.expect(BeanDefinitionParsingException.class);
|
exception.expect(BeanDefinitionParsingException.class);
|
||||||
exception.expectMessage(containsString("Cannot define both 'scope-resolver' and 'scoped-proxy' on <component-scan> tag"));
|
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]"));
|
exception.expectMessage(containsString("Offending resource: class path resource [org/springframework/context/annotation/scopedProxyInvalidConfigTests.xml]"));
|
||||||
|
|
||||||
new ClassPathXmlApplicationContext("org/springframework/context/annotation/scopedProxyInvalidConfigTests.xml");
|
new ClassPathXmlApplicationContext("org/springframework/context/annotation/scopedProxyInvalidConfigTests.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
@@ -145,9 +145,9 @@ public class ComponentScanParserTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Target({ ElementType.TYPE, ElementType.FIELD })
|
@Target({ElementType.TYPE, ElementType.FIELD})
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public static @interface CustomAnnotation {
|
public @interface CustomAnnotation {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 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.
|
||||||
@@ -53,7 +53,7 @@ public class ComponentScanParserWithUserDefinedStrategiesTests {
|
|||||||
"org/springframework/context/annotation/invalidConstructorNameGeneratorTests.xml");
|
"org/springframework/context/annotation/invalidConstructorNameGeneratorTests.xml");
|
||||||
fail("should have failed: no-arg constructor is required");
|
fail("should have failed: no-arg constructor is required");
|
||||||
}
|
}
|
||||||
catch (BeansException e) {
|
catch (BeansException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,9 +65,9 @@ public class ComponentScanParserWithUserDefinedStrategiesTests {
|
|||||||
"org/springframework/context/annotation/invalidClassNameScopeResolverTests.xml");
|
"org/springframework/context/annotation/invalidClassNameScopeResolverTests.xml");
|
||||||
fail("should have failed: no such class");
|
fail("should have failed: no such class");
|
||||||
}
|
}
|
||||||
catch (BeansException e) {
|
catch (BeansException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ class SynthesizedAnnotationInvocationHandler implements InvocationHandler {
|
|||||||
this.attributeExtractor = attributeExtractor;
|
this.attributeExtractor = attributeExtractor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||||
if (isEqualsMethod(method)) {
|
if (isEqualsMethod(method)) {
|
||||||
@@ -75,8 +76,8 @@ class SynthesizedAnnotationInvocationHandler implements InvocationHandler {
|
|||||||
return annotationType();
|
return annotationType();
|
||||||
}
|
}
|
||||||
if (!isAttributeMethod(method)) {
|
if (!isAttributeMethod(method)) {
|
||||||
String msg = String.format("Method [%s] is unsupported for synthesized annotation type [%s]", method,
|
String msg = String.format("Method [%s] is unsupported for synthesized annotation type [%s]",
|
||||||
annotationType());
|
method, annotationType());
|
||||||
throw new AnnotationConfigurationException(msg);
|
throw new AnnotationConfigurationException(msg);
|
||||||
}
|
}
|
||||||
return getAttributeValue(method);
|
return getAttributeValue(method);
|
||||||
@@ -92,9 +93,9 @@ class SynthesizedAnnotationInvocationHandler implements InvocationHandler {
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
value = this.attributeExtractor.getAttributeValue(attributeMethod);
|
value = this.attributeExtractor.getAttributeValue(attributeMethod);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
throw new IllegalStateException(String.format(
|
String msg = String.format("%s returned null for attribute name [%s] from attribute source [%s]",
|
||||||
"%s returned null for attribute name [%s] from attribute source [%s]",
|
this.attributeExtractor.getClass().getName(), attributeName, this.attributeExtractor.getSource());
|
||||||
this.attributeExtractor.getClass().getName(), attributeName, this.attributeExtractor.getSource()));
|
throw new IllegalStateException(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synthesize nested annotations before returning them.
|
// Synthesize nested annotations before returning them.
|
||||||
@@ -200,7 +201,6 @@ class SynthesizedAnnotationInvocationHandler implements InvocationHandler {
|
|||||||
* in Spring's {@link ObjectUtils} because those hash code generation
|
* in Spring's {@link ObjectUtils} because those hash code generation
|
||||||
* algorithms do not comply with the requirements specified in
|
* algorithms do not comply with the requirements specified in
|
||||||
* {@link Annotation#hashCode()}.
|
* {@link Annotation#hashCode()}.
|
||||||
*
|
|
||||||
* @param array the array to compute the hash code for
|
* @param array the array to compute the hash code for
|
||||||
*/
|
*/
|
||||||
private int hashCodeForArray(Object array) {
|
private int hashCodeForArray(Object array) {
|
||||||
|
|||||||
Reference in New Issue
Block a user