SimpleAliasRegistry logs info message for alias overriding
Issue: SPR-16871
This commit is contained in:
parent
46a89d9534
commit
74fcdea2d9
|
@ -39,6 +39,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.BeanWrapper;
|
import org.springframework.beans.BeanWrapper;
|
||||||
import org.springframework.beans.BeanWrapperImpl;
|
import org.springframework.beans.BeanWrapperImpl;
|
||||||
|
@ -1870,6 +1872,14 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expose the logger to collaborating delegates.
|
||||||
|
* @since 5.0.7
|
||||||
|
*/
|
||||||
|
Log getLogger() {
|
||||||
|
return logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Special DependencyDescriptor variant for Spring's good old autowire="byType" mode.
|
* Special DependencyDescriptor variant for Spring's good old autowire="byType" mode.
|
||||||
|
|
|
@ -32,6 +32,8 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import org.springframework.beans.BeanMetadataElement;
|
import org.springframework.beans.BeanMetadataElement;
|
||||||
import org.springframework.beans.BeanWrapper;
|
import org.springframework.beans.BeanWrapper;
|
||||||
import org.springframework.beans.BeanWrapperImpl;
|
import org.springframework.beans.BeanWrapperImpl;
|
||||||
|
@ -78,6 +80,8 @@ class ConstructorResolver {
|
||||||
|
|
||||||
private final AbstractAutowireCapableBeanFactory beanFactory;
|
private final AbstractAutowireCapableBeanFactory beanFactory;
|
||||||
|
|
||||||
|
private final Log logger;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new ConstructorResolver for the given factory and instantiation strategy.
|
* Create a new ConstructorResolver for the given factory and instantiation strategy.
|
||||||
|
@ -85,6 +89,7 @@ class ConstructorResolver {
|
||||||
*/
|
*/
|
||||||
public ConstructorResolver(AbstractAutowireCapableBeanFactory beanFactory) {
|
public ConstructorResolver(AbstractAutowireCapableBeanFactory beanFactory) {
|
||||||
this.beanFactory = beanFactory;
|
this.beanFactory = beanFactory;
|
||||||
|
this.logger = beanFactory.getLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -193,9 +198,8 @@ class ConstructorResolver {
|
||||||
getUserDeclaredConstructor(candidate), autowiring);
|
getUserDeclaredConstructor(candidate), autowiring);
|
||||||
}
|
}
|
||||||
catch (UnsatisfiedDependencyException ex) {
|
catch (UnsatisfiedDependencyException ex) {
|
||||||
if (this.beanFactory.logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
this.beanFactory.logger.trace(
|
logger.trace("Ignoring constructor [" + candidate + "] of bean '" + beanName + "': " + ex);
|
||||||
"Ignoring constructor [" + candidate + "] of bean '" + beanName + "': " + ex);
|
|
||||||
}
|
}
|
||||||
// Swallow and try next constructor.
|
// Swallow and try next constructor.
|
||||||
if (causes == null) {
|
if (causes == null) {
|
||||||
|
@ -471,9 +475,8 @@ class ConstructorResolver {
|
||||||
beanName, mbd, resolvedValues, bw, paramTypes, paramNames, candidate, autowiring);
|
beanName, mbd, resolvedValues, bw, paramTypes, paramNames, candidate, autowiring);
|
||||||
}
|
}
|
||||||
catch (UnsatisfiedDependencyException ex) {
|
catch (UnsatisfiedDependencyException ex) {
|
||||||
if (this.beanFactory.logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
this.beanFactory.logger.trace("Ignoring factory method [" + candidate +
|
logger.trace("Ignoring factory method [" + candidate + "] of bean '" + beanName + "': " + ex);
|
||||||
"] of bean '" + beanName + "': " + ex);
|
|
||||||
}
|
}
|
||||||
// Swallow and try next overloaded factory method.
|
// Swallow and try next overloaded factory method.
|
||||||
if (causes == null) {
|
if (causes == null) {
|
||||||
|
@ -733,8 +736,8 @@ class ConstructorResolver {
|
||||||
|
|
||||||
for (String autowiredBeanName : autowiredBeanNames) {
|
for (String autowiredBeanName : autowiredBeanNames) {
|
||||||
this.beanFactory.registerDependentBean(autowiredBeanName, beanName);
|
this.beanFactory.registerDependentBean(autowiredBeanName, beanName);
|
||||||
if (this.beanFactory.logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
this.beanFactory.logger.debug("Autowiring by type from bean name '" + beanName +
|
logger.debug("Autowiring by type from bean name '" + beanName +
|
||||||
"' via " + (executable instanceof Constructor ? "constructor" : "factory method") +
|
"' via " + (executable instanceof Constructor ? "constructor" : "factory method") +
|
||||||
" to bean named '" + autowiredBeanName + "'");
|
" to bean named '" + autowiredBeanName + "'");
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,6 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanCreationException;
|
import org.springframework.beans.factory.BeanCreationException;
|
||||||
import org.springframework.beans.factory.BeanCreationNotAllowedException;
|
import org.springframework.beans.factory.BeanCreationNotAllowedException;
|
||||||
import org.springframework.beans.factory.BeanCurrentlyInCreationException;
|
import org.springframework.beans.factory.BeanCurrentlyInCreationException;
|
||||||
|
@ -73,9 +70,6 @@ import org.springframework.util.StringUtils;
|
||||||
*/
|
*/
|
||||||
public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements SingletonBeanRegistry {
|
public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements SingletonBeanRegistry {
|
||||||
|
|
||||||
/** Logger available to subclasses */
|
|
||||||
protected final Log logger = LogFactory.getLog(getClass());
|
|
||||||
|
|
||||||
/** Cache of singleton objects: bean name --> bean instance */
|
/** Cache of singleton objects: bean name --> bean instance */
|
||||||
private final Map<String, Object> singletonObjects = new ConcurrentHashMap<>(256);
|
private final Map<String, Object> singletonObjects = new ConcurrentHashMap<>(256);
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,9 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.util.StringValueResolver;
|
import org.springframework.util.StringValueResolver;
|
||||||
|
@ -37,6 +40,9 @@ import org.springframework.util.StringValueResolver;
|
||||||
*/
|
*/
|
||||||
public class SimpleAliasRegistry implements AliasRegistry {
|
public class SimpleAliasRegistry implements AliasRegistry {
|
||||||
|
|
||||||
|
/** Logger available to subclasses */
|
||||||
|
protected final Log logger = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
/** Map from alias to canonical name */
|
/** Map from alias to canonical name */
|
||||||
private final Map<String, String> aliasMap = new ConcurrentHashMap<>(16);
|
private final Map<String, String> aliasMap = new ConcurrentHashMap<>(16);
|
||||||
|
|
||||||
|
@ -48,6 +54,9 @@ public class SimpleAliasRegistry implements AliasRegistry {
|
||||||
synchronized (this.aliasMap) {
|
synchronized (this.aliasMap) {
|
||||||
if (alias.equals(name)) {
|
if (alias.equals(name)) {
|
||||||
this.aliasMap.remove(alias);
|
this.aliasMap.remove(alias);
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("Alias definition '" + alias + "' ignored since it points to same name");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String registeredName = this.aliasMap.get(alias);
|
String registeredName = this.aliasMap.get(alias);
|
||||||
|
@ -57,12 +66,19 @@ public class SimpleAliasRegistry implements AliasRegistry {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!allowAliasOverriding()) {
|
if (!allowAliasOverriding()) {
|
||||||
throw new IllegalStateException("Cannot register alias '" + alias + "' for name '" +
|
throw new IllegalStateException("Cannot define alias '" + alias + "' for name '" +
|
||||||
name + "': It is already registered for name '" + registeredName + "'.");
|
name + "': It is already registered for name '" + registeredName + "'.");
|
||||||
}
|
}
|
||||||
|
if (this.logger.isInfoEnabled()) {
|
||||||
|
logger.info("Overriding alias '" + alias + "' definition for registered name '" +
|
||||||
|
registeredName + "' with new target name '" + name + "'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
checkForAliasCircle(name, alias);
|
checkForAliasCircle(name, alias);
|
||||||
this.aliasMap.put(alias, name);
|
this.aliasMap.put(alias, name);
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("Alias definition '" + alias + "' registered for name '" + name + "'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue