From d3ea2420852dc06d9ff9c21711749126163d8b57 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 17 Sep 2014 15:01:39 +0200 Subject: [PATCH] Polishing --- .../WebMvcConfigurationSupport.java | 72 ++++++++++--------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java index 5993c6de3d..7ee748fcc8 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java @@ -153,14 +153,13 @@ import org.springframework.web.util.UrlPathHelper; * libraries available on the classpath. * * - * @see EnableWebMvc - * @see WebMvcConfigurer - * @see WebMvcConfigurerAdapter - * * @author Rossen Stoyanchev * @author Brian Clozel * @author Sebastien Deleuze * @since 3.1 + * @see EnableWebMvc + * @see WebMvcConfigurer + * @see WebMvcConfigurerAdapter */ public class WebMvcConfigurationSupport implements ApplicationContextAware, ServletContextAware { @@ -181,34 +180,34 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv ClassUtils.isPresent("com.google.gson.Gson", WebMvcConfigurationSupport.class.getClassLoader()); - private ServletContext servletContext; - private ApplicationContext applicationContext; + private ServletContext servletContext; + private List interceptors; + private PathMatchConfigurer pathMatchConfigurer; + private ContentNegotiationManager contentNegotiationManager; private List> messageConverters; - private PathMatchConfigurer pathMatchConfigurer; - /** - * Set the {@link javax.servlet.ServletContext}, e.g. for resource handling, - * looking up file extensions, etc. + * Set the Spring {@link ApplicationContext}, e.g. for resource loading. */ @Override - public void setServletContext(ServletContext servletContext) { - this.servletContext = servletContext; + public void setApplicationContext(ApplicationContext applicationContext) { + this.applicationContext = applicationContext; } /** - * Set the Spring {@link ApplicationContext}, e.g. for resource loading. + * Set the {@link javax.servlet.ServletContext}, e.g. for resource handling, + * looking up file extensions, etc. */ @Override - public void setApplicationContext(ApplicationContext applicationContext) { - this.applicationContext = applicationContext; + public void setServletContext(ServletContext servletContext) { + this.servletContext = servletContext; } @@ -239,23 +238,8 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv if (configurer.getUrlPathHelper() != null) { handlerMapping.setUrlPathHelper(configurer.getUrlPathHelper()); } - return handlerMapping; - } - - protected PathMatchConfigurer getPathMatchConfigurer() { - if (this.pathMatchConfigurer == null) { - this.pathMatchConfigurer = new PathMatchConfigurer(); - configurePathMatch(this.pathMatchConfigurer); - } - return this.pathMatchConfigurer; - } - /** - * Override this method to configure path matching options. - * @see PathMatchConfigurer - * @since 4.0.3 - */ - public void configurePathMatch(PathMatchConfigurer configurer) { + return handlerMapping; } /** @@ -282,6 +266,27 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv protected void addInterceptors(InterceptorRegistry registry) { } + /** + * Callback for building the {@link PathMatchConfigurer}. + * Delegates to {@link #configurePathMatch}. + * @since 4.1 + */ + protected PathMatchConfigurer getPathMatchConfigurer() { + if (this.pathMatchConfigurer == null) { + this.pathMatchConfigurer = new PathMatchConfigurer(); + configurePathMatch(this.pathMatchConfigurer); + } + return this.pathMatchConfigurer; + } + + /** + * Override this method to configure path matching options. + * @see PathMatchConfigurer + * @since 4.0.3 + */ + public void configurePathMatch(PathMatchConfigurer configurer) { + } + /** * Return a {@link ContentNegotiationManager} instance to use to determine * requested {@linkplain MediaType media types} in a given request. @@ -295,8 +300,8 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv try { this.contentNegotiationManager = configurer.getContentNegotiationManager(); } - catch (Exception e) { - throw new BeanInitializationException("Could not create ContentNegotiationManager", e); + catch (Exception ex) { + throw new BeanInitializationException("Could not create ContentNegotiationManager", ex); } } return this.contentNegotiationManager; @@ -680,7 +685,6 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv public void configureAsyncSupport(AsyncSupportConfigurer configurer) { } - /** * Return an instance of {@link CompositeUriComponentsContributor} for use with * {@link org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder}.