Add load-on-startup property to DispatcherServlet
Closes gh-2481
This commit is contained in:
parent
dc35367453
commit
699d083cec
|
@ -110,6 +110,8 @@ public class DispatcherServletAutoConfiguration {
|
|||
ServletRegistrationBean registration = new ServletRegistrationBean(
|
||||
dispatcherServlet(), this.server.getServletMapping());
|
||||
registration.setName(DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
|
||||
registration.setLoadOnStartup(
|
||||
this.webMvcProperties.getServlet().getLoadOnStartup());
|
||||
if (this.multipartConfig != null) {
|
||||
registration.setMultipartConfig(this.multipartConfig);
|
||||
}
|
||||
|
|
|
@ -84,6 +84,8 @@ public class WebMvcProperties {
|
|||
|
||||
private final Async async = new Async();
|
||||
|
||||
private final Servlet servlet = new Servlet();
|
||||
|
||||
private final View view = new View();
|
||||
|
||||
public DefaultMessageCodesResolver.Format getMessageCodesResolverFormat() {
|
||||
|
@ -164,6 +166,10 @@ public class WebMvcProperties {
|
|||
return this.async;
|
||||
}
|
||||
|
||||
public Servlet getServlet() {
|
||||
return this.servlet;
|
||||
}
|
||||
|
||||
public View getView() {
|
||||
return this.view;
|
||||
}
|
||||
|
@ -187,6 +193,23 @@ public class WebMvcProperties {
|
|||
|
||||
}
|
||||
|
||||
public static class Servlet {
|
||||
|
||||
/**
|
||||
* Load on startup priority of the dispatcher servlet.
|
||||
*/
|
||||
private int loadOnStartup = -1;
|
||||
|
||||
public int getLoadOnStartup() {
|
||||
return this.loadOnStartup;
|
||||
}
|
||||
|
||||
public void setLoadOnStartup(int loadOnStartup) {
|
||||
this.loadOnStartup = loadOnStartup;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class View {
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,6 +22,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.UnsatisfiedDependencyException;
|
||||
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
||||
import org.springframework.boot.web.servlet.MultipartConfigFactory;
|
||||
|
@ -151,17 +152,19 @@ public class DispatcherServletAutoConfigurationTests {
|
|||
this.context.register(ServerPropertiesAutoConfiguration.class,
|
||||
DispatcherServletAutoConfiguration.class);
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.mvc.throw-exception-if-no-handler-found:true");
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.mvc.dispatch-options-request:true");
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.mvc.dispatch-trace-request:true");
|
||||
"spring.mvc.throw-exception-if-no-handler-found:true",
|
||||
"spring.mvc.dispatch-options-request:true",
|
||||
"spring.mvc.dispatch-trace-request:true",
|
||||
"spring.mvc.servlet.load-on-startup=5");
|
||||
this.context.refresh();
|
||||
DispatcherServlet bean = this.context.getBean(DispatcherServlet.class);
|
||||
assertThat(bean).extracting("throwExceptionIfNoHandlerFound")
|
||||
.containsExactly(true);
|
||||
assertThat(bean).extracting("dispatchOptionsRequest").containsExactly(true);
|
||||
assertThat(bean).extracting("dispatchTraceRequest").containsExactly(true);
|
||||
assertThat(
|
||||
new DirectFieldAccessor(this.context.getBean("dispatcherServletRegistration"))
|
||||
.getPropertyValue("loadOnStartup")).isEqualTo(5);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
|
|
@ -337,6 +337,7 @@ content into your application; rather pick only the properties that you need.
|
|||
spring.mvc.locale= # Locale to use.
|
||||
spring.mvc.media-types.*= # Maps file extensions to media types for content negotiation.
|
||||
spring.mvc.message-codes-resolver-format= # Formatting strategy for message codes. For instance `PREFIX_ERROR_CODE`.
|
||||
spring.mvc.servlet.load-on-startup=-1 # Load on startup priority of the Spring Web Services servlet.
|
||||
spring.mvc.static-path-pattern=/** # Path pattern used for static resources.
|
||||
spring.mvc.throw-exception-if-no-handler-found=false # If a "NoHandlerFoundException" should be thrown if no Handler was found to process a request.
|
||||
spring.mvc.view.prefix= # Spring MVC view prefix.
|
||||
|
|
Loading…
Reference in New Issue