@ -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" ) ;
* 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 .
@ -28,10 +28,11 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier ;
import java.lang.reflect.Modifier ;
import java.net.MalformedURLException ;
import java.net.MalformedURLException ;
import java.net.URL ;
import java.net.URL ;
import java.util.ArrayList ;
import java.util.Collections ;
import java.util.Collections ;
import java.util.HashSet ;
import java.util.HashSet ;
import java.util.LinkedHashSet ;
import java.util.LinkedHashSet ;
import java.util.LinkedLi st ;
import java.util.List ;
import java.util.Map ;
import java.util.Map ;
import java.util.Set ;
import java.util.Set ;
import java.util.concurrent.ConcurrentHashMap ;
import java.util.concurrent.ConcurrentHashMap ;
@ -47,7 +48,6 @@ import javax.xml.ws.WebServiceRef;
import org.springframework.aop.TargetSource ;
import org.springframework.aop.TargetSource ;
import org.springframework.aop.framework.ProxyFactory ;
import org.springframework.aop.framework.ProxyFactory ;
import org.springframework.beans.BeanUtils ;
import org.springframework.beans.BeanUtils ;
import org.springframework.beans.BeansException ;
import org.springframework.beans.PropertyValues ;
import org.springframework.beans.PropertyValues ;
import org.springframework.beans.factory.BeanCreationException ;
import org.springframework.beans.factory.BeanCreationException ;
import org.springframework.beans.factory.BeanFactory ;
import org.springframework.beans.factory.BeanFactory ;
@ -300,18 +300,18 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
}
}
@Override
@Override
public Object postProcessBeforeInstantiation ( Class < ? > beanClass , String beanName ) throws BeansException {
public Object postProcessBeforeInstantiation ( Class < ? > beanClass , String beanName ) {
return null ;
return null ;
}
}
@Override
@Override
public boolean postProcessAfterInstantiation ( Object bean , String beanName ) throws BeansException {
public boolean postProcessAfterInstantiation ( Object bean , String beanName ) {
return true ;
return true ;
}
}
@Override
@Override
public PropertyValues postProcessPropertyValues (
public PropertyValues postProcessPropertyValues (
PropertyValues pvs , PropertyDescriptor [ ] pds , Object bean , String beanName ) throws BeansException {
PropertyValues pvs , PropertyDescriptor [ ] pds , Object bean , String beanName ) {
InjectionMetadata metadata = findResourceMetadata ( beanName , bean . getClass ( ) , pvs ) ;
InjectionMetadata metadata = findResourceMetadata ( beanName , bean . getClass ( ) , pvs ) ;
try {
try {
@ -345,12 +345,11 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
}
}
private InjectionMetadata buildResourceMetadata ( final Class < ? > clazz ) {
private InjectionMetadata buildResourceMetadata ( final Class < ? > clazz ) {
LinkedLi st < InjectionMetadata . InjectedElement > elements = new Linked List< > ( ) ;
List < InjectionMetadata . InjectedElement > elements = new Array List< > ( ) ;
Class < ? > targetClass = clazz ;
Class < ? > targetClass = clazz ;
do {
do {
final LinkedList < InjectionMetadata . InjectedElement > currElements =
final List < InjectionMetadata . InjectedElement > currElements = new ArrayList < > ( ) ;
new LinkedList < > ( ) ;
ReflectionUtils . doWithLocalFields ( targetClass , field - > {
ReflectionUtils . doWithLocalFields ( targetClass , field - > {
if ( webServiceRefClass ! = null & & field . isAnnotationPresent ( webServiceRefClass ) ) {
if ( webServiceRefClass ! = null & & field . isAnnotationPresent ( webServiceRefClass ) ) {
@ -369,7 +368,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
if ( Modifier . isStatic ( field . getModifiers ( ) ) ) {
if ( Modifier . isStatic ( field . getModifiers ( ) ) ) {
throw new IllegalStateException ( "@Resource annotation is not supported on static fields" ) ;
throw new IllegalStateException ( "@Resource annotation is not supported on static fields" ) ;
}
}
if ( ! ignoredResourceTypes . contains ( field . getType ( ) . getName ( ) ) ) {
if ( ! this . ignoredResourceTypes . contains ( field . getType ( ) . getName ( ) ) ) {
currElements . add ( new ResourceElement ( field , field , null ) ) ;
currElements . add ( new ResourceElement ( field , field , null ) ) ;
}
}
}
}
@ -409,7 +408,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
if ( paramTypes . length ! = 1 ) {
if ( paramTypes . length ! = 1 ) {
throw new IllegalStateException ( "@Resource annotation requires a single-arg method: " + method ) ;
throw new IllegalStateException ( "@Resource annotation requires a single-arg method: " + method ) ;
}
}
if ( ! ignoredResourceTypes . contains ( paramTypes [ 0 ] . getName ( ) ) ) {
if ( ! this . ignoredResourceTypes . contains ( paramTypes [ 0 ] . getName ( ) ) ) {
PropertyDescriptor pd = BeanUtils . findPropertyForMethod ( bridgedMethod , clazz ) ;
PropertyDescriptor pd = BeanUtils . findPropertyForMethod ( bridgedMethod , clazz ) ;
currElements . add ( new ResourceElement ( method , bridgedMethod , pd ) ) ;
currElements . add ( new ResourceElement ( method , bridgedMethod , pd ) ) ;
}
}
@ -468,9 +467,11 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
* @param element the descriptor for the annotated field / method
* @param element the descriptor for the annotated field / method
* @param requestingBeanName the name of the requesting bean
* @param requestingBeanName the name of the requesting bean
* @return the resource object ( never { @code null } )
* @return the resource object ( never { @code null } )
* @throws BeansException if we failed to obtain the target resource
* @throws NoSuchBeanDefinitionException if no corresponding target resource found
* /
* /
protected Object getResource ( LookupElement element , @Nullable String requestingBeanName ) throws BeansException {
protected Object getResource ( LookupElement element , @Nullable String requestingBeanName )
throws NoSuchBeanDefinitionException {
if ( StringUtils . hasLength ( element . mappedName ) ) {
if ( StringUtils . hasLength ( element . mappedName ) ) {
return this . jndiFactory . getBean ( element . mappedName , element . lookupType ) ;
return this . jndiFactory . getBean ( element . mappedName , element . lookupType ) ;
}
}
@ -491,10 +492,10 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
* @param element the descriptor for the annotated field / method
* @param element the descriptor for the annotated field / method
* @param requestingBeanName the name of the requesting bean
* @param requestingBeanName the name of the requesting bean
* @return the resource object ( never { @code null } )
* @return the resource object ( never { @code null } )
* @throws BeansException if we failed to obtain the target resource
* @throws NoSuchBeanDefinitionException if no corresponding target resource found
* /
* /
protected Object autowireResource ( BeanFactory factory , LookupElement element , @Nullable String requestingBeanName )
protected Object autowireResource ( BeanFactory factory , LookupElement element , @Nullable String requestingBeanName )
throws Beans Exception {
throws NoSuchBeanDefinition Exception {
Object resource ;
Object resource ;
Set < String > autowiredBeanNames ;
Set < String > autowiredBeanNames ;