Update information on WebApplicationContext hierarchy
Issue: SPR-16041
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -20,13 +20,11 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.http.server.reactive.ServletHttpHandlerAdapter;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.reactive.DispatcherHandler;
|
||||
|
||||
/**
|
||||
* Base class for {@link org.springframework.web.WebApplicationInitializer}
|
||||
* implementations that register a {@link DispatcherHandler} configured with annotated
|
||||
* {@link org.springframework.context.annotation.Configuration @Configuration} classes in the
|
||||
* servlet context, wrapping it in a {@link ServletHttpHandlerAdapter}.
|
||||
* {@link org.springframework.web.WebApplicationInitializer WebApplicationInitializer}
|
||||
* to register a {@code DispatcherHandler}, wrapping it in a
|
||||
* {@link ServletHttpHandlerAdapter}, and use Java-based Spring configuration.
|
||||
*
|
||||
* <p>Concrete implementations are required to implement {@link #getConfigClasses()}.
|
||||
* Further template and customization methods are provided by
|
||||
@@ -38,6 +36,7 @@ import org.springframework.web.reactive.DispatcherHandler;
|
||||
public abstract class AbstractAnnotationConfigDispatcherHandlerInitializer
|
||||
extends AbstractDispatcherHandlerInitializer {
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>This implementation creates an {@link AnnotationConfigApplicationContext},
|
||||
@@ -45,19 +44,18 @@ public abstract class AbstractAnnotationConfigDispatcherHandlerInitializer
|
||||
*/
|
||||
@Override
|
||||
protected ApplicationContext createApplicationContext() {
|
||||
AnnotationConfigApplicationContext servletAppContext = new AnnotationConfigApplicationContext();
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
Class<?>[] configClasses = getConfigClasses();
|
||||
if (!ObjectUtils.isEmpty(configClasses)) {
|
||||
servletAppContext.register(configClasses);
|
||||
context.register(configClasses);
|
||||
}
|
||||
return servletAppContext;
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify {@link org.springframework.context.annotation.Configuration @Configuration}
|
||||
* and/or {@link org.springframework.stereotype.Component @Component} classes to be
|
||||
* provided to the {@linkplain #createApplicationContext() application context}.
|
||||
* @return the configuration classes for the dispatcher servlet application context
|
||||
* Specify {@code @Configuration} and/or {@code @Component} classes for
|
||||
* the {@linkplain #createApplicationContext() application context}.
|
||||
* @return the configuration for the application context
|
||||
*/
|
||||
protected abstract Class<?>[] getConfigClasses();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -34,16 +34,15 @@ import org.springframework.web.server.adapter.HttpWebHandlerAdapter;
|
||||
|
||||
/**
|
||||
* Base class for {@link org.springframework.web.WebApplicationInitializer}
|
||||
* implementations that register a {@link DispatcherHandler} in the servlet context, wrapping it in
|
||||
* a {@link ServletHttpHandlerAdapter}.
|
||||
* implementations that register a {@link DispatcherHandler} in the servlet
|
||||
* context, wrapping it in a {@link ServletHttpHandlerAdapter}.
|
||||
*
|
||||
* <p>Concrete implementations are required to implement
|
||||
* {@link #createApplicationContext()}, which gets invoked from
|
||||
* {@link #registerDispatcherHandler(ServletContext)}. Further customization can be achieved by
|
||||
* overriding {@link #customizeRegistration(ServletRegistration.Dynamic)}.
|
||||
* <p>Most applications should consider extending the Spring Java config, sub-class
|
||||
* {@link AbstractAnnotationConfigDispatcherHandlerInitializer}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 5.0
|
||||
* @see AbstractServletHttpHandlerAdapterInitializer
|
||||
*/
|
||||
public abstract class AbstractDispatcherHandlerInitializer implements WebApplicationInitializer {
|
||||
|
||||
|
||||
@@ -27,16 +27,15 @@ import org.springframework.web.WebApplicationInitializer;
|
||||
|
||||
/**
|
||||
* Base class for {@link org.springframework.web.WebApplicationInitializer}
|
||||
* implementations that register a {@link ServletHttpHandlerAdapter} in the servlet context.
|
||||
* implementations that register a {@link ServletHttpHandlerAdapter} in the
|
||||
* servlet context.
|
||||
*
|
||||
* <p>Concrete implementations are required to implement
|
||||
* {@link #createHttpHandler()}, as well as {@link #getServletMappings()},
|
||||
* both of which get invoked from {@link #registerHandlerAdapter(ServletContext)}.
|
||||
* Further customization can be achieved by overriding
|
||||
* {@link #customizeRegistration(ServletRegistration.Dynamic)}.
|
||||
* <p>See {@link AbstractDispatcherHandlerInitializer} if registering a
|
||||
* {@link org.springframework.web.reactive.DispatcherHandler DispatcherHandler}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 5.0
|
||||
* @see AbstractDispatcherHandlerInitializer
|
||||
*/
|
||||
public abstract class AbstractServletHttpHandlerAdapterInitializer implements WebApplicationInitializer {
|
||||
|
||||
@@ -67,12 +66,12 @@ public abstract class AbstractServletHttpHandlerAdapterInitializer implements We
|
||||
Assert.hasLength(servletName, "getServletName() must not return empty or null");
|
||||
|
||||
HttpHandler httpHandler = createHttpHandler();
|
||||
Assert.notNull(httpHandler,
|
||||
"createHttpHandler() did not return a HttpHandler for servlet [" + servletName + "]");
|
||||
Assert.notNull(httpHandler, "createHttpHandler() did not return a HttpHandler" +
|
||||
"for servlet [" + servletName + "]");
|
||||
|
||||
ServletHttpHandlerAdapter servlet = createServlet(httpHandler);
|
||||
Assert.notNull(servlet,
|
||||
"createHttpHandler() did not return a ServletHttpHandlerAdapter for servlet [" + servletName + "]");
|
||||
Assert.notNull(servlet, "createHttpHandler() did not return a ServletHttpHandlerAdapter " +
|
||||
"for servlet [" + servletName + "]");
|
||||
|
||||
ServletRegistration.Dynamic registration = servletContext.addServlet(servletName, servlet);
|
||||
Assert.notNull(registration,
|
||||
@@ -102,8 +101,8 @@ public abstract class AbstractServletHttpHandlerAdapterInitializer implements We
|
||||
|
||||
/**
|
||||
* Create a {@link ServletHttpHandlerAdapter} with the specified .
|
||||
* <p>Default implementation returns a {@code ServletHttpHandlerAdapter} with the provided
|
||||
* {@code httpHandler}.
|
||||
* <p>Default implementation returns a {@code ServletHttpHandlerAdapter}
|
||||
* with the provided {@code httpHandler}.
|
||||
*/
|
||||
protected ServletHttpHandlerAdapter createServlet(HttpHandler httpHandler) {
|
||||
return new ServletHttpHandlerAdapter(httpHandler);
|
||||
|
||||
Reference in New Issue
Block a user