MergedBeanDefinitionPostProcessors clear internal caches on bean reset
Issue: SPR-17126
This commit is contained in:
parent
69c6a40c50
commit
e64c6dfa3d
|
|
@ -233,6 +233,12 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
|||
metadata.checkConfigMembers(beanDefinition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetBeanDefinition(String beanName) {
|
||||
this.lookupMethodsChecked.remove(beanName);
|
||||
this.injectionMetadataCache.remove(beanName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, final String beanName)
|
||||
|
|
|
|||
|
|
@ -415,8 +415,8 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
|||
throws BeansException {
|
||||
|
||||
Object result = existingBean;
|
||||
for (BeanPostProcessor beanProcessor : getBeanPostProcessors()) {
|
||||
Object current = beanProcessor.postProcessBeforeInitialization(result, beanName);
|
||||
for (BeanPostProcessor processor : getBeanPostProcessors()) {
|
||||
Object current = processor.postProcessBeforeInitialization(result, beanName);
|
||||
if (current == null) {
|
||||
return result;
|
||||
}
|
||||
|
|
@ -430,8 +430,8 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
|||
throws BeansException {
|
||||
|
||||
Object result = existingBean;
|
||||
for (BeanPostProcessor beanProcessor : getBeanPostProcessors()) {
|
||||
Object current = beanProcessor.postProcessAfterInitialization(result, beanName);
|
||||
for (BeanPostProcessor processor : getBeanPostProcessors()) {
|
||||
Object current = processor.postProcessAfterInitialization(result, beanName);
|
||||
if (current == null) {
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ import org.springframework.beans.factory.SmartInitializingSingleton;
|
|||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.config.DependencyDescriptor;
|
||||
|
|
@ -969,6 +970,13 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
|||
// (e.g. the default StaticMessageSource in a StaticApplicationContext).
|
||||
destroySingleton(beanName);
|
||||
|
||||
// Notify all post-processors that the specified bean definition has been reset.
|
||||
for (BeanPostProcessor processor : getBeanPostProcessors()) {
|
||||
if (processor instanceof MergedBeanDefinitionPostProcessor) {
|
||||
((MergedBeanDefinitionPostProcessor) processor).resetBeanDefinition(beanName);
|
||||
}
|
||||
}
|
||||
|
||||
// Reset all bean definitions that have the given bean as parent (recursively).
|
||||
for (String bdName : this.beanDefinitionNames) {
|
||||
if (!beanName.equals(bdName)) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
|
|
@ -45,4 +45,13 @@ public interface MergedBeanDefinitionPostProcessor extends BeanPostProcessor {
|
|||
*/
|
||||
void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName);
|
||||
|
||||
/**
|
||||
* A notification that the bean definition for the specified name has been reset,
|
||||
* and that this post-processor should clear any metadata for the affected bean.
|
||||
* @param beanName the name of the bean
|
||||
* @since 5.1
|
||||
*/
|
||||
default void resetBeanDefinition(String beanName) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -299,6 +299,11 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
|
|||
metadata.checkConfigMembers(beanDefinition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetBeanDefinition(String beanName) {
|
||||
this.injectionMetadataCache.remove(beanName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -334,6 +334,11 @@ public class PersistenceAnnotationBeanPostProcessor
|
|||
metadata.checkConfigMembers(beanDefinition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetBeanDefinition(String beanName) {
|
||||
this.injectionMetadataCache.remove(beanName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) {
|
||||
return null;
|
||||
|
|
|
|||
Loading…
Reference in New Issue