aligned with recent changes in CommonAnnotationBeanPostProcessor
Issue: SPR-9176 Issue: SPR-9627
This commit is contained in:
parent
04af54ad4c
commit
68c5f20bc7
|
@ -406,15 +406,15 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||||
try {
|
try {
|
||||||
Method method = ReflectionUtils.findMethod(annotation.annotationType(), this.requiredParameterName);
|
Method method = ReflectionUtils.findMethod(annotation.annotationType(), this.requiredParameterName);
|
||||||
if (method == null) {
|
if (method == null) {
|
||||||
// annotations like @Inject, @Value and @Resource don't have a method
|
// annotations like @Inject and @Value don't have a method (attribute) named "required"
|
||||||
// (attribute) named "required" -> default to required status
|
// -> default to required status
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return (this.requiredParameterValue == (Boolean) ReflectionUtils.invokeMethod(method, annotation));
|
return (this.requiredParameterValue == (Boolean) ReflectionUtils.invokeMethod(method, annotation));
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
// an exception was thrown during reflective invocation of the required
|
// an exception was thrown during reflective invocation of the required attribute
|
||||||
// attribute -> default to required status
|
// -> default to required status
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -425,11 +425,12 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||||
private void registerDependentBeans(String beanName, Set<String> autowiredBeanNames) {
|
private void registerDependentBeans(String beanName, Set<String> autowiredBeanNames) {
|
||||||
if (beanName != null) {
|
if (beanName != null) {
|
||||||
for (String autowiredBeanName : autowiredBeanNames) {
|
for (String autowiredBeanName : autowiredBeanNames) {
|
||||||
beanFactory.registerDependentBean(autowiredBeanName, beanName);
|
if (this.beanFactory.containsBean(autowiredBeanName)) {
|
||||||
|
this.beanFactory.registerDependentBean(autowiredBeanName, beanName);
|
||||||
|
}
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug(
|
logger.debug("Autowiring by type from bean name '" + beanName +
|
||||||
"Autowiring by type from bean name '" + beanName + "' to bean named '" + autowiredBeanName +
|
"' to bean named '" + autowiredBeanName + "'");
|
||||||
"'");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -441,11 +442,11 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||||
private Object resolvedCachedArgument(String beanName, Object cachedArgument) {
|
private Object resolvedCachedArgument(String beanName, Object cachedArgument) {
|
||||||
if (cachedArgument instanceof DependencyDescriptor) {
|
if (cachedArgument instanceof DependencyDescriptor) {
|
||||||
DependencyDescriptor descriptor = (DependencyDescriptor) cachedArgument;
|
DependencyDescriptor descriptor = (DependencyDescriptor) cachedArgument;
|
||||||
TypeConverter typeConverter = beanFactory.getTypeConverter();
|
TypeConverter typeConverter = this.beanFactory.getTypeConverter();
|
||||||
return beanFactory.resolveDependency(descriptor, beanName, null, typeConverter);
|
return this.beanFactory.resolveDependency(descriptor, beanName, null, typeConverter);
|
||||||
}
|
}
|
||||||
else if (cachedArgument instanceof RuntimeBeanReference) {
|
else if (cachedArgument instanceof RuntimeBeanReference) {
|
||||||
return beanFactory.getBean(((RuntimeBeanReference) cachedArgument).getBeanName());
|
return this.beanFactory.getBean(((RuntimeBeanReference) cachedArgument).getBeanName());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return cachedArgument;
|
return cachedArgument;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2010 the original author or authors.
|
* Copyright 2002-2012 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.
|
||||||
|
@ -118,6 +118,11 @@ public final class AutowiredAnnotationBeanPostProcessorTests {
|
||||||
assertSame(tb, bean.getTestBean4());
|
assertSame(tb, bean.getTestBean4());
|
||||||
assertSame(ntb, bean.getNestedTestBean());
|
assertSame(ntb, bean.getNestedTestBean());
|
||||||
assertSame(bf, bean.getBeanFactory());
|
assertSame(bf, bean.getBeanFactory());
|
||||||
|
|
||||||
|
String[] depBeans = bf.getDependenciesForBean("annotatedBean");
|
||||||
|
assertEquals(2, depBeans.length);
|
||||||
|
assertEquals("testBean", depBeans[0]);
|
||||||
|
assertEquals("nestedTestBean", depBeans[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue