diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java index ac80c0e059..f882a5da56 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -120,7 +120,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean protected final Log logger = LogFactory.getLog(getClass()); private final Set> autowiredAnnotationTypes = - new LinkedHashSet>(); + new LinkedHashSet>(4); private String requiredParameterName = "required"; @@ -484,7 +484,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean } private AnnotationAttributes findAutowiredAnnotation(AccessibleObject ao) { - if (ao.getAnnotations().length > 0) { + if (ao.getAnnotations().length > 0) { // autowiring annotations have to be local for (Class type : this.autowiredAnnotationTypes) { AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(ao, type); if (attributes != null) { @@ -594,11 +594,10 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean registerDependentBeans(beanName, autowiredBeanNames); if (autowiredBeanNames.size() == 1) { String autowiredBeanName = autowiredBeanNames.iterator().next(); - if (beanFactory.containsBean(autowiredBeanName)) { - if (beanFactory.isTypeMatch(autowiredBeanName, field.getType())) { - this.cachedFieldValue = new ShortcutDependencyDescriptor( - desc, autowiredBeanName, field.getType()); - } + if (beanFactory.containsBean(autowiredBeanName) && + beanFactory.isTypeMatch(autowiredBeanName, field.getType())) { + this.cachedFieldValue = new ShortcutDependencyDescriptor( + desc, autowiredBeanName, field.getType()); } } } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java index ee6b59ea4b..8e6ecb3a5f 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -342,10 +342,12 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa * Determine a suggested value from any of the given candidate annotations. */ protected Object findValue(Annotation[] annotationsToSearch) { - AnnotationAttributes attr = AnnotatedElementUtils.getMergedAnnotationAttributes( - AnnotatedElementUtils.forAnnotations(annotationsToSearch), this.valueAnnotationType); - if (attr != null) { - return extractValue(attr); + if (annotationsToSearch.length > 0) { // qualifier annotations have to be local + AnnotationAttributes attr = AnnotatedElementUtils.getMergedAnnotationAttributes( + AnnotatedElementUtils.forAnnotations(annotationsToSearch), this.valueAnnotationType); + if (attr != null) { + return extractValue(attr); + } } return null; } diff --git a/spring-context/src/test/java/org/springframework/cache/annotation/AnnotationCacheOperationSourceTests.java b/spring-context/src/test/java/org/springframework/cache/annotation/AnnotationCacheOperationSourceTests.java index b9d9baff49..1322e63d75 100644 --- a/spring-context/src/test/java/org/springframework/cache/annotation/AnnotationCacheOperationSourceTests.java +++ b/spring-context/src/test/java/org/springframework/cache/annotation/AnnotationCacheOperationSourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -52,13 +52,13 @@ public class AnnotationCacheOperationSourceTests { @Test - public void singularAnnotation() throws Exception { + public void singularAnnotation() { Collection ops = getOps(AnnotatedClass.class, "singular", 1); assertTrue(ops.iterator().next() instanceof CacheableOperation); } @Test - public void multipleAnnotation() throws Exception { + public void multipleAnnotation() { Collection ops = getOps(AnnotatedClass.class, "multiple", 2); Iterator it = ops.iterator(); assertTrue(it.next() instanceof CacheableOperation); @@ -66,7 +66,7 @@ public class AnnotationCacheOperationSourceTests { } @Test - public void caching() throws Exception { + public void caching() { Collection ops = getOps(AnnotatedClass.class, "caching", 2); Iterator it = ops.iterator(); assertTrue(it.next() instanceof CacheableOperation); @@ -74,18 +74,18 @@ public class AnnotationCacheOperationSourceTests { } @Test - public void emptyCaching() throws Exception { + public void emptyCaching() { getOps(AnnotatedClass.class, "emptyCaching", 0); } @Test - public void singularStereotype() throws Exception { + public void singularStereotype() { Collection ops = getOps(AnnotatedClass.class, "singleStereotype", 1); assertTrue(ops.iterator().next() instanceof CacheEvictOperation); } @Test - public void multipleStereotypes() throws Exception { + public void multipleStereotypes() { Collection ops = getOps(AnnotatedClass.class, "multipleStereotype", 3); Iterator it = ops.iterator(); assertTrue(it.next() instanceof CacheableOperation); @@ -98,7 +98,7 @@ public class AnnotationCacheOperationSourceTests { } @Test - public void singleComposedAnnotation() throws Exception { + public void singleComposedAnnotation() { Collection ops = getOps(AnnotatedClass.class, "singleComposed", 2); Iterator it = ops.iterator(); @@ -114,7 +114,7 @@ public class AnnotationCacheOperationSourceTests { } @Test - public void multipleComposedAnnotations() throws Exception { + public void multipleComposedAnnotations() { Collection ops = getOps(AnnotatedClass.class, "multipleComposed", 4); Iterator it = ops.iterator(); diff --git a/src/asciidoc/web-view.adoc b/src/asciidoc/web-view.adoc index f35cfb17a6..4e4ee86525 100644 --- a/src/asciidoc/web-view.adoc +++ b/src/asciidoc/web-view.adoc @@ -1712,7 +1712,7 @@ for more configuration examples. The `MarshallingView` uses an XML `Marshaller` defined in the `org.springframework.oxm` package to render the response content as XML. The object to be marshalled can be set -explicitly using ``MarhsallingView``'s `modelKey` bean property. Alternatively, the view +explicitly using ``MarshallingView``'s `modelKey` bean property. Alternatively, the view will iterate over all model properties and marshal the first type that is supported by the `Marshaller`. For more information on the functionality in the `org.springframework.oxm` package refer to the chapter <