Update intializer for the reactive servlet adapter

Move the AbstractServletHttpHandlerAdapterInitializer together with
the other two base classes in spring-web-reactive. Since the
interface is in the web package, this avoids a package cycle.
Also add a mention in the reference.

Issue: SPR-14713
This commit is contained in:
Rossen Stoyanchev 2016-09-16 12:54:22 -04:00
parent 2b57a4d618
commit cf2112f539
5 changed files with 18 additions and 31 deletions

View File

@ -28,8 +28,7 @@ import org.springframework.web.reactive.DispatcherHandler;
* {@link org.springframework.context.annotation.Configuration @Configuration} classes in the
* servlet context, wrapping it in a {@link ServletHttpHandlerAdapter}.
*
* <p>Concrete implementations are required to implement {@link #getConfigClasses()} and
* {@link #getServletMapping()}.
* <p>Concrete implementations are required to implement {@link #getConfigClasses()}.
* Further template and customization methods are provided by
* {@link AbstractDispatcherHandlerInitializer}.
*

View File

@ -130,10 +130,9 @@ public abstract class AbstractDispatcherHandlerInitializer implements WebApplica
/**
* Refresh the given application context, if necessary.
*/
protected void refreshApplicationContext(ApplicationContext applicationContext) {
if (applicationContext instanceof ConfigurableApplicationContext) {
ConfigurableApplicationContext cac =
(ConfigurableApplicationContext) applicationContext;
protected void refreshApplicationContext(ApplicationContext context) {
if (context instanceof ConfigurableApplicationContext) {
ConfigurableApplicationContext cac = (ConfigurableApplicationContext) context;
if (!cac.isActive()) {
cac.refresh();
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.http.server.reactive.support;
package org.springframework.web.reactive.support;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
@ -24,7 +24,6 @@ import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.http.server.reactive.ServletHttpHandlerAdapter;
import org.springframework.util.Assert;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.WebApplicationContext;
/**
* Base class for {@link org.springframework.web.WebApplicationInitializer}
@ -47,6 +46,7 @@ public abstract class AbstractServletHttpHandlerAdapterInitializer
*/
public static final String DEFAULT_SERVLET_NAME = "http-handler-adapter";
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
registerHandlerAdapter(servletContext);
@ -104,7 +104,7 @@ public abstract class AbstractServletHttpHandlerAdapterInitializer
protected abstract HttpHandler createHttpHandler();
/**
* Create a {@link ServletHttpHandlerAdapter} with the specified {@link WebApplicationContext}.
* Create a {@link ServletHttpHandlerAdapter} with the specified .
* <p>Default implementation returns a {@code ServletHttpHandlerAdapter} with the provided
* {@code httpHandler}.
*/

View File

@ -1,21 +0,0 @@
/*
* Copyright 2002-2016 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Support classes for Spring's reactive HTTP server abstraction.
*/
package org.springframework.http.server.reactive.support;

View File

@ -198,7 +198,7 @@ An `HttpHandler` can then be installed in each supported runtime:
[source,java,indent=0]
[subs="verbatim,quotes"]
----
// Tomcat and Jetty
// Tomcat and Jetty (also see notes below)
HttpServlet servlet = new ServletHttpHandlerAdapter(httpHandler);
...
@ -218,6 +218,16 @@ Undertow server = Undertow.builder().addHttpListener(port, host).setHandler(http
server.start();
----
[NOTE]
====
For Servlet runtimes you can use the `AbstractAnnotationConfigDispatcherHandlerInitializer`,
which as a `WebApplicationInitializer` is auto-detected by Servlet containers
and it registers for you the `ServletHttpHandlerAdapter` shown above.
Only implement one method to point to your Spring Java configuration classes.
====
[[web-reactive-getting-started-M1]]
=== Extent of Support in 5.0 M1