Skip to content

Commit b16a322

Browse files
committed
Polishing
1 parent a409233 commit b16a322

File tree

4 files changed

+24
-23
lines changed

4 files changed

+24
-23
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -120,7 +120,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
120120
protected final Log logger = LogFactory.getLog(getClass());
121121

122122
private final Set<Class<? extends Annotation>> autowiredAnnotationTypes =
123-
new LinkedHashSet<Class<? extends Annotation>>();
123+
new LinkedHashSet<Class<? extends Annotation>>(4);
124124

125125
private String requiredParameterName = "required";
126126

@@ -484,7 +484,7 @@ public void doWith(Method method) throws IllegalArgumentException, IllegalAccess
484484
}
485485

486486
private AnnotationAttributes findAutowiredAnnotation(AccessibleObject ao) {
487-
if (ao.getAnnotations().length > 0) {
487+
if (ao.getAnnotations().length > 0) { // autowiring annotations have to be local
488488
for (Class<? extends Annotation> type : this.autowiredAnnotationTypes) {
489489
AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(ao, type);
490490
if (attributes != null) {
@@ -594,11 +594,10 @@ protected void inject(Object bean, String beanName, PropertyValues pvs) throws T
594594
registerDependentBeans(beanName, autowiredBeanNames);
595595
if (autowiredBeanNames.size() == 1) {
596596
String autowiredBeanName = autowiredBeanNames.iterator().next();
597-
if (beanFactory.containsBean(autowiredBeanName)) {
598-
if (beanFactory.isTypeMatch(autowiredBeanName, field.getType())) {
599-
this.cachedFieldValue = new ShortcutDependencyDescriptor(
600-
desc, autowiredBeanName, field.getType());
601-
}
597+
if (beanFactory.containsBean(autowiredBeanName) &&
598+
beanFactory.isTypeMatch(autowiredBeanName, field.getType())) {
599+
this.cachedFieldValue = new ShortcutDependencyDescriptor(
600+
desc, autowiredBeanName, field.getType());
602601
}
603602
}
604603
}

spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -342,10 +342,12 @@ public Object getSuggestedValue(DependencyDescriptor descriptor) {
342342
* Determine a suggested value from any of the given candidate annotations.
343343
*/
344344
protected Object findValue(Annotation[] annotationsToSearch) {
345-
AnnotationAttributes attr = AnnotatedElementUtils.getMergedAnnotationAttributes(
346-
AnnotatedElementUtils.forAnnotations(annotationsToSearch), this.valueAnnotationType);
347-
if (attr != null) {
348-
return extractValue(attr);
345+
if (annotationsToSearch.length > 0) { // qualifier annotations have to be local
346+
AnnotationAttributes attr = AnnotatedElementUtils.getMergedAnnotationAttributes(
347+
AnnotatedElementUtils.forAnnotations(annotationsToSearch), this.valueAnnotationType);
348+
if (attr != null) {
349+
return extractValue(attr);
350+
}
349351
}
350352
return null;
351353
}

spring-context/src/test/java/org/springframework/cache/annotation/AnnotationCacheOperationSourceTests.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -52,40 +52,40 @@ public class AnnotationCacheOperationSourceTests {
5252

5353

5454
@Test
55-
public void singularAnnotation() throws Exception {
55+
public void singularAnnotation() {
5656
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singular", 1);
5757
assertTrue(ops.iterator().next() instanceof CacheableOperation);
5858
}
5959

6060
@Test
61-
public void multipleAnnotation() throws Exception {
61+
public void multipleAnnotation() {
6262
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multiple", 2);
6363
Iterator<CacheOperation> it = ops.iterator();
6464
assertTrue(it.next() instanceof CacheableOperation);
6565
assertTrue(it.next() instanceof CacheEvictOperation);
6666
}
6767

6868
@Test
69-
public void caching() throws Exception {
69+
public void caching() {
7070
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "caching", 2);
7171
Iterator<CacheOperation> it = ops.iterator();
7272
assertTrue(it.next() instanceof CacheableOperation);
7373
assertTrue(it.next() instanceof CacheEvictOperation);
7474
}
7575

7676
@Test
77-
public void emptyCaching() throws Exception {
77+
public void emptyCaching() {
7878
getOps(AnnotatedClass.class, "emptyCaching", 0);
7979
}
8080

8181
@Test
82-
public void singularStereotype() throws Exception {
82+
public void singularStereotype() {
8383
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singleStereotype", 1);
8484
assertTrue(ops.iterator().next() instanceof CacheEvictOperation);
8585
}
8686

8787
@Test
88-
public void multipleStereotypes() throws Exception {
88+
public void multipleStereotypes() {
8989
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multipleStereotype", 3);
9090
Iterator<CacheOperation> it = ops.iterator();
9191
assertTrue(it.next() instanceof CacheableOperation);
@@ -98,7 +98,7 @@ public void multipleStereotypes() throws Exception {
9898
}
9999

100100
@Test
101-
public void singleComposedAnnotation() throws Exception {
101+
public void singleComposedAnnotation() {
102102
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singleComposed", 2);
103103
Iterator<CacheOperation> it = ops.iterator();
104104

@@ -114,7 +114,7 @@ public void singleComposedAnnotation() throws Exception {
114114
}
115115

116116
@Test
117-
public void multipleComposedAnnotations() throws Exception {
117+
public void multipleComposedAnnotations() {
118118
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multipleComposed", 4);
119119
Iterator<CacheOperation> it = ops.iterator();
120120

src/asciidoc/web-view.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ for more configuration examples.
17121712

17131713
The `MarshallingView` uses an XML `Marshaller` defined in the `org.springframework.oxm`
17141714
package to render the response content as XML. The object to be marshalled can be set
1715-
explicitly using ``MarhsallingView``'s `modelKey` bean property. Alternatively, the view
1715+
explicitly using ``MarshallingView``'s `modelKey` bean property. Alternatively, the view
17161716
will iterate over all model properties and marshal the first type that is supported
17171717
by the `Marshaller`. For more information on the functionality in the
17181718
`org.springframework.oxm` package refer to the chapter <<oxm,Marshalling XML using O/X

0 commit comments

Comments
 (0)