From cf2112f5398c74f1d7279fea17b4db3a4dc6f4e1 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Fri, 16 Sep 2016 12:54:22 -0400 Subject: [PATCH] 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 --- ...ionConfigDispatcherHandlerInitializer.java | 3 +-- .../AbstractDispatcherHandlerInitializer.java | 7 +++---- ...tServletHttpHandlerAdapterInitializer.java | 6 +++--- .../server/reactive/support/package-info.java | 21 ------------------- src/asciidoc/web-reactive.adoc | 12 ++++++++++- 5 files changed, 18 insertions(+), 31 deletions(-) rename {spring-web/src/main/java/org/springframework/http/server => spring-web-reactive/src/main/java/org/springframework/web}/reactive/support/AbstractServletHttpHandlerAdapterInitializer.java (96%) delete mode 100644 spring-web/src/main/java/org/springframework/http/server/reactive/support/package-info.java diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/support/AbstractAnnotationConfigDispatcherHandlerInitializer.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/support/AbstractAnnotationConfigDispatcherHandlerInitializer.java index 642339a514..59339ddfc5 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/support/AbstractAnnotationConfigDispatcherHandlerInitializer.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/support/AbstractAnnotationConfigDispatcherHandlerInitializer.java @@ -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}. * - *

Concrete implementations are required to implement {@link #getConfigClasses()} and - * {@link #getServletMapping()}. + *

Concrete implementations are required to implement {@link #getConfigClasses()}. * Further template and customization methods are provided by * {@link AbstractDispatcherHandlerInitializer}. * diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/support/AbstractDispatcherHandlerInitializer.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/support/AbstractDispatcherHandlerInitializer.java index a2fccc73a8..1599c5c025 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/support/AbstractDispatcherHandlerInitializer.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/support/AbstractDispatcherHandlerInitializer.java @@ -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(); } diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/support/AbstractServletHttpHandlerAdapterInitializer.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/support/AbstractServletHttpHandlerAdapterInitializer.java similarity index 96% rename from spring-web/src/main/java/org/springframework/http/server/reactive/support/AbstractServletHttpHandlerAdapterInitializer.java rename to spring-web-reactive/src/main/java/org/springframework/web/reactive/support/AbstractServletHttpHandlerAdapterInitializer.java index 8a6f67924a..792708566e 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/support/AbstractServletHttpHandlerAdapterInitializer.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/support/AbstractServletHttpHandlerAdapterInitializer.java @@ -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 . *

Default implementation returns a {@code ServletHttpHandlerAdapter} with the provided * {@code httpHandler}. */ diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/support/package-info.java b/spring-web/src/main/java/org/springframework/http/server/reactive/support/package-info.java deleted file mode 100644 index 2f8756faec..0000000000 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/support/package-info.java +++ /dev/null @@ -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; \ No newline at end of file diff --git a/src/asciidoc/web-reactive.adoc b/src/asciidoc/web-reactive.adoc index ce83202b1d..a470bcb049 100644 --- a/src/asciidoc/web-reactive.adoc +++ b/src/asciidoc/web-reactive.adoc @@ -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