Avoid early initializations for reactive support

This commit flags the `BeanPostProcessor` registered by the reactive
embedded support as `synthetic` so that it doesn't trigger an early
initialization of other components.

See gh-8467
This commit is contained in:
Stephane Nicoll 2017-03-06 08:27:28 +01:00
parent 36d6ab41a2
commit 546338ac80
2 changed files with 14 additions and 11 deletions

View File

@ -84,9 +84,11 @@ public class ReactiveWebServerAutoConfiguration {
}
if (ObjectUtils.isEmpty(this.beanFactory.getBeanNamesForType(
ReactiveWebServerCustomizerBeanPostProcessor.class, true, false))) {
RootBeanDefinition beanDefinition = new RootBeanDefinition(
ReactiveWebServerCustomizerBeanPostProcessor.class);
beanDefinition.setSynthetic(true);
registry.registerBeanDefinition(
"reactiveWebServerCustomizerBeanPostProcessor",
new RootBeanDefinition(ReactiveWebServerCustomizerBeanPostProcessor.class));
"reactiveWebServerCustomizerBeanPostProcessor", beanDefinition);
}
}

View File

@ -22,29 +22,30 @@ import java.util.Collections;
import java.util.List;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
/**
* {@link BeanPostProcessor} that applies all {@link ReactiveWebServerCustomizer}s
* from the bean factory to {@link ConfigurableReactiveWebServer} beans.
*
*
* @author Brian Clozel
* @author Stephane Nicoll
* @since 2.0.0
*/
public class ReactiveWebServerCustomizerBeanPostProcessor
implements BeanPostProcessor, ApplicationContextAware {
implements BeanPostProcessor, BeanFactoryAware {
private ApplicationContext applicationContext;
private ListableBeanFactory beanFactory;
private List<ReactiveWebServerCustomizer> customizers;
@Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
this.applicationContext = applicationContext;
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = (ListableBeanFactory) beanFactory;
}
@Override
@ -73,7 +74,7 @@ public class ReactiveWebServerCustomizerBeanPostProcessor
if (this.customizers == null) {
// Look up does not include the parent context
this.customizers = new ArrayList<ReactiveWebServerCustomizer>(
this.applicationContext
this.beanFactory
.getBeansOfType(ReactiveWebServerCustomizer.class,
false, false)
.values());