提交 4e47006a 编写于 作者: J Juergen Hoeller

Merge branch '5.1.x'

/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
......@@ -184,6 +184,20 @@ public class ConfigurationClassPostProcessorTests {
assertSupportForComposedAnnotationWithExclude(beanDefinition);
}
@Test
public void postProcessorWorksWithExtendedConfigurationWithAttributeOverrideForExcludesFilterUsingReflection() {
RootBeanDefinition beanDefinition = new RootBeanDefinition(
ExtendedConfigurationWithAttributeOverrideForExcludeFilter.class);
assertSupportForComposedAnnotationWithExclude(beanDefinition);
}
@Test
public void postProcessorWorksWithExtendedConfigurationWithAttributeOverrideForExcludesFilterUsingAsm() {
RootBeanDefinition beanDefinition = new RootBeanDefinition(
ExtendedConfigurationWithAttributeOverrideForExcludeFilter.class.getName());
assertSupportForComposedAnnotationWithExclude(beanDefinition);
}
@Test
public void postProcessorWorksWithComposedComposedConfigurationWithAttributeOverridesUsingReflection() {
RootBeanDefinition beanDefinition = new RootBeanDefinition(
......@@ -1515,6 +1529,15 @@ public class ConfigurationClassPostProcessorTests {
public static class ComposedConfigurationWithAttributeOverrideForExcludeFilter {
}
@ComponentScan(basePackages = "org.springframework.context.annotation.componentscan.base", excludeFilters = {})
public static class BaseConfigurationWithEmptyExcludeFilters {
}
@ComponentScan(basePackages = "org.springframework.context.annotation.componentscan.simple",
excludeFilters = @ComponentScan.Filter(Component.class))
public static class ExtendedConfigurationWithAttributeOverrideForExcludeFilter extends BaseConfigurationWithEmptyExcludeFilters {
}
@ComposedConfigurationWithAttributeOverrides
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
......
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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.
......@@ -363,7 +363,7 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
private void assertAttributeType(String attributeName, Object attributeValue, Class<?> expectedType) {
if (!expectedType.isInstance(attributeValue)) {
throw new IllegalArgumentException(String.format(
"Attribute '%s' is of type [%s], but [%s] was expected in attributes for annotation [%s]",
"Attribute '%s' is of type %s, but %s was expected in attributes for annotation [%s]",
attributeName, attributeValue.getClass().getSimpleName(), expectedType.getSimpleName(),
this.displayName));
}
......
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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.
......@@ -28,6 +28,7 @@ import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.ObjectUtils;
......@@ -124,7 +125,7 @@ abstract class AnnotationReadingVisitorUtils {
// Get the unmerged list of attributes for the target annotation.
List<AnnotationAttributes> attributesList = attributesMap.get(annotationName);
if (attributesList == null || attributesList.isEmpty()) {
if (CollectionUtils.isEmpty(attributesList)) {
return null;
}
......
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
......@@ -89,7 +89,11 @@ class RecursiveAnnotationArrayVisitor extends AbstractRecursiveAnnotationVisitor
try {
Class<?> attributeType = annotationType.getMethod(this.attributeName).getReturnType();
if (attributeType.isArray()) {
this.attributes.put(this.attributeName, Array.newInstance(attributeType.getComponentType(), 0));
Class<?> elementType = attributeType.getComponentType();
if (elementType.isAnnotation()) {
elementType = AnnotationAttributes.class;
}
this.attributes.put(this.attributeName, Array.newInstance(elementType, 0));
}
}
catch (NoSuchMethodException ex) {
......
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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.
......@@ -154,7 +154,7 @@ public class AnnotationAttributesTests {
public void getEnumWithTypeMismatch() {
attributes.put("color", "RED");
exception.expect(IllegalArgumentException.class);
exception.expectMessage(containsString("Attribute 'color' is of type [String], but [Enum] was expected"));
exception.expectMessage(containsString("Attribute 'color' is of type String, but Enum was expected"));
attributes.getEnum("color");
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册