Commit 74c48767 authored by Phillip Webb's avatar Phillip Webb

Add beanFactory context constructors

Align `WebServer` application contexts with Spring Framework by allowing
a custom beanFactory to be used on construction.

Fixes gh-8547
parent 99afc4bc
...@@ -18,6 +18,7 @@ package org.springframework.boot.web.reactive.context; ...@@ -18,6 +18,7 @@ package org.springframework.boot.web.reactive.context;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanNameGenerator; import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader; import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.AnnotationConfigUtils; import org.springframework.context.annotation.AnnotationConfigUtils;
...@@ -69,6 +70,19 @@ public class AnnotationConfigReactiveWebServerApplicationContext ...@@ -69,6 +70,19 @@ public class AnnotationConfigReactiveWebServerApplicationContext
this.scanner = new ClassPathBeanDefinitionScanner(this); this.scanner = new ClassPathBeanDefinitionScanner(this);
} }
/**
* Create a new {@link AnnotationConfigReactiveWebServerApplicationContext} with the
* given {@code DefaultListableBeanFactory}. The context needs to be populated through
* {@link #register} calls and then manually {@linkplain #refresh refreshed}.
* @param beanFactory the DefaultListableBeanFactory instance to use for this context
*/
public AnnotationConfigReactiveWebServerApplicationContext(
DefaultListableBeanFactory beanFactory) {
super(beanFactory);
this.reader = new AnnotatedBeanDefinitionReader(this);
this.scanner = new ClassPathBeanDefinitionScanner(this);
}
/** /**
* Create a new {@link AnnotationConfigReactiveWebServerApplicationContext}, deriving * Create a new {@link AnnotationConfigReactiveWebServerApplicationContext}, deriving
* bean definitions from the given annotated classes and automatically refreshing the * bean definitions from the given annotated classes and automatically refreshing the
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package org.springframework.boot.web.reactive.context; package org.springframework.boot.web.reactive.context;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory; import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory;
import org.springframework.boot.web.server.WebServer; import org.springframework.boot.web.server.WebServer;
import org.springframework.context.ApplicationContextException; import org.springframework.context.ApplicationContextException;
...@@ -35,9 +36,21 @@ public class ReactiveWebServerApplicationContext ...@@ -35,9 +36,21 @@ public class ReactiveWebServerApplicationContext
private volatile WebServer webServer; private volatile WebServer webServer;
/**
* Create a new {@link ReactiveWebServerApplicationContext}.
*/
public ReactiveWebServerApplicationContext() { public ReactiveWebServerApplicationContext() {
} }
/**
* Create a new {@link ReactiveWebServerApplicationContext} with the given
* {@code DefaultListableBeanFactory}.
* @param beanFactory the DefaultListableBeanFactory instance to use for this context
*/
public ReactiveWebServerApplicationContext(DefaultListableBeanFactory beanFactory) {
super(beanFactory);
}
@Override @Override
public final void refresh() throws BeansException, IllegalStateException { public final void refresh() throws BeansException, IllegalStateException {
try { try {
......
...@@ -18,6 +18,7 @@ package org.springframework.boot.web.servlet.context; ...@@ -18,6 +18,7 @@ package org.springframework.boot.web.servlet.context;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanNameGenerator; import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader; import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
import org.springframework.context.annotation.AnnotationConfigUtils; import org.springframework.context.annotation.AnnotationConfigUtils;
import org.springframework.context.annotation.AnnotationScopeMetadataResolver; import org.springframework.context.annotation.AnnotationScopeMetadataResolver;
...@@ -67,6 +68,19 @@ public class AnnotationConfigServletWebServerApplicationContext ...@@ -67,6 +68,19 @@ public class AnnotationConfigServletWebServerApplicationContext
this.scanner = new ClassPathBeanDefinitionScanner(this); this.scanner = new ClassPathBeanDefinitionScanner(this);
} }
/**
* Create a new {@link AnnotationConfigServletWebServerApplicationContext} with the
* given {@code DefaultListableBeanFactory}. The context needs to be populated through
* {@link #register} calls and then manually {@linkplain #refresh refreshed}.
* @param beanFactory the DefaultListableBeanFactory instance to use for this context
*/
public AnnotationConfigServletWebServerApplicationContext(
DefaultListableBeanFactory beanFactory) {
super(beanFactory);
this.reader = new AnnotatedBeanDefinitionReader(this);
this.scanner = new ClassPathBeanDefinitionScanner(this);
}
/** /**
* Create a new {@link AnnotationConfigServletWebServerApplicationContext}, deriving * Create a new {@link AnnotationConfigServletWebServerApplicationContext}, deriving
* bean definitions from the given annotated classes and automatically refreshing the * bean definitions from the given annotated classes and automatically refreshing the
......
...@@ -36,6 +36,7 @@ import org.apache.commons.logging.LogFactory; ...@@ -36,6 +36,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.Scope; import org.springframework.beans.factory.config.Scope;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.web.server.WebServer; import org.springframework.boot.web.server.WebServer;
import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletContextInitializer; import org.springframework.boot.web.servlet.ServletContextInitializer;
...@@ -105,6 +106,21 @@ public class ServletWebServerApplicationContext extends GenericWebApplicationCon ...@@ -105,6 +106,21 @@ public class ServletWebServerApplicationContext extends GenericWebApplicationCon
private String namespace; private String namespace;
/**
* Create a new {@link ServletWebServerApplicationContext}.
*/
public ServletWebServerApplicationContext() {
}
/**
* Create a new {@link ServletWebServerApplicationContext} with the given
* {@code DefaultListableBeanFactory}.
* @param beanFactory the DefaultListableBeanFactory instance to use for this context
*/
public ServletWebServerApplicationContext(DefaultListableBeanFactory beanFactory) {
super(beanFactory);
}
/** /**
* Register ServletContextAwareProcessor. * Register ServletContextAwareProcessor.
* @see ServletContextAwareProcessor * @see ServletContextAwareProcessor
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment