Fix bridge method detection for class hierarchies
Prior to this change, @Autowired injection against an instance of a subclass having different visibility than its superclass would fail if the @Autowired method is declared only in the superclass. This is due to an apparent change in the rules around bridge method generation between Java 5 and Java 6, and possibly even varying across compiler vendors. Now, BridgeMethodResolver is used consistently when detecting @Autowired, @Inject and @Resource metadata to bypass these bridge methods if they exist. Issue: SPR-7900
This commit is contained in:
@@ -50,6 +50,7 @@ import org.springframework.beans.factory.config.InstantiationAwareBeanPostProces
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.core.BridgeMethodResolver;
|
||||
import org.springframework.core.GenericTypeResolver;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.Ordered;
|
||||
@@ -370,6 +371,9 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||
|
||||
private Annotation findAutowiredAnnotation(AccessibleObject ao) {
|
||||
for (Class<? extends Annotation> type : this.autowiredAnnotationTypes) {
|
||||
if (ao instanceof Method) {
|
||||
ao = BridgeMethodResolver.findBridgedMethod((Method)ao);
|
||||
}
|
||||
Annotation annotation = ao.getAnnotation(type);
|
||||
if (annotation != null) {
|
||||
return annotation;
|
||||
|
||||
Reference in New Issue
Block a user