@Bean methods are allowed to override existing bean definitions with a role other than ROLE_APPLICATION now (e.g. framework-generated default beans)
Also, DefaultListableBeanFactory logs a warning when overriding an application definition with a framework-generated definition now, which is expected to be an accident. Issue: SPR-10607
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -229,11 +229,11 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
|
||||
|
||||
/**
|
||||
* Get the role hint for this {@code BeanDefinition}. The role hint
|
||||
* provides tools with an indication of the importance of a particular
|
||||
* {@code BeanDefinition}.
|
||||
* provides the frameworks as well as tools with an indication of
|
||||
* the role and importance of a particular {@code BeanDefinition}.
|
||||
* @see #ROLE_APPLICATION
|
||||
* @see #ROLE_INFRASTRUCTURE
|
||||
* @see #ROLE_SUPPORT
|
||||
* @see #ROLE_INFRASTRUCTURE
|
||||
*/
|
||||
int getRole();
|
||||
|
||||
|
||||
@@ -691,13 +691,21 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
}
|
||||
|
||||
synchronized (this.beanDefinitionMap) {
|
||||
Object oldBeanDefinition = this.beanDefinitionMap.get(beanName);
|
||||
BeanDefinition oldBeanDefinition = this.beanDefinitionMap.get(beanName);
|
||||
if (oldBeanDefinition != null) {
|
||||
if (!this.allowBeanDefinitionOverriding) {
|
||||
throw new BeanDefinitionStoreException(beanDefinition.getResourceDescription(), beanName,
|
||||
"Cannot register bean definition [" + beanDefinition + "] for bean '" + beanName +
|
||||
"': There is already [" + oldBeanDefinition + "] bound.");
|
||||
}
|
||||
else if (oldBeanDefinition.getRole() < beanDefinition.getRole()) {
|
||||
// e.g. was ROLE_APPLICATION, now overriding with ROLE_SUPPORT or ROLE_INFRASTRUCTURE
|
||||
if (this.logger.isWarnEnabled()) {
|
||||
this.logger.warn("Overriding user-defined bean definition for bean '" + beanName +
|
||||
" with a framework-generated bean definition ': replacing [" +
|
||||
oldBeanDefinition + "] with [" + beanDefinition + "]");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this.logger.isInfoEnabled()) {
|
||||
this.logger.info("Overriding bean definition for bean '" + beanName +
|
||||
|
||||
Reference in New Issue
Block a user