|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2020 the original author or authors. |
|
|
|
* Copyright 2002-2021 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. |
|
|
|
@ -146,22 +146,27 @@ import org.springframework.util.StringValueResolver; |
|
|
|
public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBeanPostProcessor |
|
|
|
public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBeanPostProcessor |
|
|
|
implements InstantiationAwareBeanPostProcessor, BeanFactoryAware, Serializable { |
|
|
|
implements InstantiationAwareBeanPostProcessor, BeanFactoryAware, Serializable { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Defensive reference to JNDI API for JDK 9+ (optional java.naming module)
|
|
|
|
|
|
|
|
private static final boolean jndiPresent = ClassUtils.isPresent( |
|
|
|
|
|
|
|
"javax.naming.InitialContext", CommonAnnotationBeanPostProcessor.class.getClassLoader()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final Set<Class<? extends Annotation>> resourceAnnotationTypes = new LinkedHashSet<>(4); |
|
|
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
private static final Class<? extends Annotation> webServiceRefClass; |
|
|
|
private static final Class<? extends Annotation> webServiceRefClass; |
|
|
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
private static final Class<? extends Annotation> ejbClass; |
|
|
|
private static final Class<? extends Annotation> ejbClass; |
|
|
|
|
|
|
|
|
|
|
|
private static final Set<Class<? extends Annotation>> resourceAnnotationTypes = new LinkedHashSet<>(4); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static { |
|
|
|
static { |
|
|
|
webServiceRefClass = loadAnnotationType("javax.xml.ws.WebServiceRef"); |
|
|
|
|
|
|
|
ejbClass = loadAnnotationType("javax.ejb.EJB"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resourceAnnotationTypes.add(Resource.class); |
|
|
|
resourceAnnotationTypes.add(Resource.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
webServiceRefClass = loadAnnotationType("javax.xml.ws.WebServiceRef"); |
|
|
|
if (webServiceRefClass != null) { |
|
|
|
if (webServiceRefClass != null) { |
|
|
|
resourceAnnotationTypes.add(webServiceRefClass); |
|
|
|
resourceAnnotationTypes.add(webServiceRefClass); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ejbClass = loadAnnotationType("javax.ejb.EJB"); |
|
|
|
if (ejbClass != null) { |
|
|
|
if (ejbClass != null) { |
|
|
|
resourceAnnotationTypes.add(ejbClass); |
|
|
|
resourceAnnotationTypes.add(ejbClass); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -174,7 +179,8 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean |
|
|
|
|
|
|
|
|
|
|
|
private boolean alwaysUseJndiLookup = false; |
|
|
|
private boolean alwaysUseJndiLookup = false; |
|
|
|
|
|
|
|
|
|
|
|
private transient BeanFactory jndiFactory = new SimpleJndiBeanFactory(); |
|
|
|
@Nullable |
|
|
|
|
|
|
|
private transient BeanFactory jndiFactory; |
|
|
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
private transient BeanFactory resourceFactory; |
|
|
|
private transient BeanFactory resourceFactory; |
|
|
|
@ -199,6 +205,11 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean |
|
|
|
setInitAnnotationType(PostConstruct.class); |
|
|
|
setInitAnnotationType(PostConstruct.class); |
|
|
|
setDestroyAnnotationType(PreDestroy.class); |
|
|
|
setDestroyAnnotationType(PreDestroy.class); |
|
|
|
ignoreResourceType("javax.xml.ws.WebServiceContext"); |
|
|
|
ignoreResourceType("javax.xml.ws.WebServiceContext"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// java.naming module present on JDK 9+?
|
|
|
|
|
|
|
|
if (jndiPresent) { |
|
|
|
|
|
|
|
this.jndiFactory = new SimpleJndiBeanFactory(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -464,6 +475,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean |
|
|
|
public void releaseTarget(Object target) { |
|
|
|
public void releaseTarget(Object target) { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
ProxyFactory pf = new ProxyFactory(); |
|
|
|
ProxyFactory pf = new ProxyFactory(); |
|
|
|
pf.setTargetSource(ts); |
|
|
|
pf.setTargetSource(ts); |
|
|
|
if (element.lookupType.isInterface()) { |
|
|
|
if (element.lookupType.isInterface()) { |
|
|
|
@ -484,12 +496,23 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean |
|
|
|
protected Object getResource(LookupElement element, @Nullable String requestingBeanName) |
|
|
|
protected Object getResource(LookupElement element, @Nullable String requestingBeanName) |
|
|
|
throws NoSuchBeanDefinitionException { |
|
|
|
throws NoSuchBeanDefinitionException { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// JNDI lookup to perform?
|
|
|
|
|
|
|
|
String jndiName = null; |
|
|
|
if (StringUtils.hasLength(element.mappedName)) { |
|
|
|
if (StringUtils.hasLength(element.mappedName)) { |
|
|
|
return this.jndiFactory.getBean(element.mappedName, element.lookupType); |
|
|
|
jndiName = element.mappedName; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (this.alwaysUseJndiLookup) { |
|
|
|
|
|
|
|
jndiName = element.name; |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.alwaysUseJndiLookup) { |
|
|
|
if (jndiName != null) { |
|
|
|
return this.jndiFactory.getBean(element.name, element.lookupType); |
|
|
|
if (this.jndiFactory == null) { |
|
|
|
|
|
|
|
throw new NoSuchBeanDefinitionException(element.lookupType, |
|
|
|
|
|
|
|
"No JNDI factory configured - specify the 'jndiFactory' property"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return this.jndiFactory.getBean(jndiName, element.lookupType); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Regular resource autowiring
|
|
|
|
if (this.resourceFactory == null) { |
|
|
|
if (this.resourceFactory == null) { |
|
|
|
throw new NoSuchBeanDefinitionException(element.lookupType, |
|
|
|
throw new NoSuchBeanDefinitionException(element.lookupType, |
|
|
|
"No resource factory configured - specify the 'resourceFactory' property"); |
|
|
|
"No resource factory configured - specify the 'resourceFactory' property"); |
|
|
|
|