From 5307a87d1ad7c28e1f1a2887ab86ea3b09b5a326 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 24 Jan 2014 19:19:32 +0100 Subject: [PATCH] Polishing Issue: SPR-11357 --- .../AbstractContextLoaderInitializer.java | 14 ++++---- ...ionConfigDispatcherServletInitializer.java | 18 +++++----- .../AbstractDispatcherServletInitializer.java | 36 +++++++++---------- ...nfigDispatcherServletInitializerTests.java | 1 + 4 files changed, 34 insertions(+), 35 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/context/AbstractContextLoaderInitializer.java b/spring-web/src/main/java/org/springframework/web/context/AbstractContextLoaderInitializer.java index e8f86cee15..d38e739876 100644 --- a/spring-web/src/main/java/org/springframework/web/context/AbstractContextLoaderInitializer.java +++ b/spring-web/src/main/java/org/springframework/web/context/AbstractContextLoaderInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -25,12 +25,12 @@ import org.apache.commons.logging.LogFactory; import org.springframework.web.WebApplicationInitializer; /** - * Convenient base class for {@link WebApplicationInitializer} implementations that - * register a {@link ContextLoaderListener} in the servlet context. + * Convenient base class for {@link WebApplicationInitializer} implementations + * that register a {@link ContextLoaderListener} in the servlet context. * - *

The only method required to be implemented by subclasses is {@link - * #createRootApplicationContext()}, which gets invoked from {@link - * #registerContextLoaderListener(javax.servlet.ServletContext)}. + *

The only method required to be implemented by subclasses is + * {@link #createRootApplicationContext()}, which gets invoked from + * {@link #registerContextLoaderListener(ServletContext)}. * * @author Arjen Poutsma * @author Chris Beams @@ -64,7 +64,7 @@ public abstract class AbstractContextLoaderInitializer implements WebApplication } /** - * Create the "root" application context to be provided to the + * Create the "root" application context to be provided to the * {@code ContextLoaderListener}. *

The returned context is delegated to * {@link ContextLoaderListener#ContextLoaderListener(WebApplicationContext)} and will diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractAnnotationConfigDispatcherServletInitializer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractAnnotationConfigDispatcherServletInitializer.java index 845a19fccd..6a1777fe10 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractAnnotationConfigDispatcherServletInitializer.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractAnnotationConfigDispatcherServletInitializer.java @@ -21,16 +21,16 @@ import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; /** - * Base class for {@link org.springframework.web.WebApplicationInitializer - * WebApplicationInitializer} implementations that register a {@link - * org.springframework.web.servlet.DispatcherServlet DispatcherServlet} - * configured with annotated classes, e.g. Spring's {@link - * org.springframework.context.annotation.Configuration @Configuration} classes. + * Base class for {@link org.springframework.web.WebApplicationInitializer} + * implementations that register a + * {@link org.springframework.web.servlet.DispatcherServlet DispatcherServlet} + * configured with annotated classes, e.g. Spring's + * {@link org.springframework.context.annotation.Configuration @Configuration} classes. * *

Concrete implementations are required to implement {@link #getRootConfigClasses()} - * and {@link #getServletConfigClasses()} as well as {@link #getServletMappings()}. Further - * template and customization methods are provided by {@link - * AbstractDispatcherServletInitializer}. + * and {@link #getServletConfigClasses()} as well as {@link #getServletMappings()}. + * Further template and customization methods are provided by + * {@link AbstractDispatcherServletInitializer}. * * @author Arjen Poutsma * @author Chris Beams @@ -88,7 +88,7 @@ public abstract class AbstractAnnotationConfigDispatcherServletInitializer * provided to the {@linkplain #createServletApplicationContext() dispatcher servlet * application context}. * @return the configuration classes for the dispatcher servlet application context - * (may not be empty or {@code null}). + * (may not be empty or {@code null}) */ protected abstract Class[] getServletConfigClasses(); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractDispatcherServletInitializer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractDispatcherServletInitializer.java index 0e36b558df..4b97870005 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractDispatcherServletInitializer.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractDispatcherServletInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -33,14 +33,13 @@ import org.springframework.web.context.WebApplicationContext; import org.springframework.web.servlet.DispatcherServlet; /** - * Base class for {@link org.springframework.web.WebApplicationInitializer - * WebApplicationInitializer} implementations that register a {@link DispatcherServlet} in - * the servlet context. + * Base class for {@link org.springframework.web.WebApplicationInitializer} + * implementations that register a {@link DispatcherServlet} in the servlet context. * - *

Concrete implementations are required to implement {@link - * #createServletApplicationContext()}, as well as {@link #getServletMappings()}, both of - * which gets invoked from {@link #registerDispatcherServlet(ServletContext)}. Further - * customization can be achieved by overriding + *

Concrete implementations are required to implement + * {@link #createServletApplicationContext()}, as well as {@link #getServletMappings()}, + * both of which get invoked from {@link #registerDispatcherServlet(ServletContext)}. + * Further customization can be achieved by overriding * {@link #customizeRegistration(ServletRegistration.Dynamic)}. * *

Because this class extends from {@link AbstractContextLoaderInitializer}, concrete @@ -80,10 +79,10 @@ public abstract class AbstractDispatcherServletInitializer extends AbstractConte * @param servletContext the context to register the servlet against */ protected void registerDispatcherServlet(ServletContext servletContext) { - String servletName = this.getServletName(); + String servletName = getServletName(); Assert.hasLength(servletName, "getServletName() may not return empty or null"); - WebApplicationContext servletAppContext = this.createServletApplicationContext(); + WebApplicationContext servletAppContext = createServletApplicationContext(); Assert.notNull(servletAppContext, "createServletApplicationContext() did not return an application " + "context for servlet [" + servletName + "]"); @@ -105,7 +104,7 @@ public abstract class AbstractDispatcherServletInitializer extends AbstractConte } } - this.customizeRegistration(registration); + customizeRegistration(registration); } /** @@ -120,22 +119,22 @@ public abstract class AbstractDispatcherServletInitializer extends AbstractConte /** * Create a servlet application context to be provided to the {@code DispatcherServlet}. *

The returned context is delegated to Spring's - * {@link DispatcherServlet#DispatcherServlet(WebApplicationContext)} As such, it - * typically contains controllers, view resolvers, locale resolvers, and other + * {@link DispatcherServlet#DispatcherServlet(WebApplicationContext)}. As such, + * it typically contains controllers, view resolvers, locale resolvers, and other * web-related beans. * @see #registerDispatcherServlet(ServletContext) */ protected abstract WebApplicationContext createServletApplicationContext(); /** - * Specify the servlet mapping(s) for the {@code DispatcherServlet}, e.g. '/', '/app', etc. + * Specify the servlet mapping(s) for the {@code DispatcherServlet} — + * for example {@code "/"}, {@code "/app"}, etc. * @see #registerDispatcherServlet(ServletContext) */ protected abstract String[] getServletMappings(); /** - * Specify filters to add and also map to the {@code DispatcherServlet}. - * + * Specify filters to add and map to the {@code DispatcherServlet}. * @return an array of filters or {@code null} * @see #registerServletFilter(ServletContext, Filter) */ @@ -154,9 +153,8 @@ public abstract class AbstractDispatcherServletInitializer extends AbstractConte * {@code FORWARD}, {@code INCLUDE}, and conditionally {@code ASYNC} depending * on the return value of {@link #isAsyncSupported() asyncSupported} * - *

If the above defaults are not suitable or insufficient, register - * filters directly with the {@code ServletContext}. - * + *

If the above defaults are not suitable or insufficient, override this + * method and register filters directly with the {@code ServletContext}. * @param servletContext the servlet context to register filters with * @param filter the filter to be registered * @return the filter registration diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/support/AnnotationConfigDispatcherServletInitializerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/support/AnnotationConfigDispatcherServletInitializerTests.java index 6bb5c2f111..6e023649fa 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/support/AnnotationConfigDispatcherServletInitializerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/support/AnnotationConfigDispatcherServletInitializerTests.java @@ -179,6 +179,7 @@ public class AnnotationConfigDispatcherServletInitializerTests { private class MyMockServletContext extends MockServletContext { + @Override public void addListener(T t) { if (t instanceof ServletContextListener) { ((ServletContextListener) t).contextInitialized(new ServletContextEvent(this));