From 883ac319bced893a3068ac482ce6e99ed4865566 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Mon, 13 Jun 2011 12:20:25 +0000 Subject: [PATCH] SPR-8430 Rename WebMvcConfiguration to DelegatingWebMvcConfiguration, make it public and make delegation methods final --- ...ava => DelegatingWebMvcConfiguration.java} | 38 ++++++++----------- .../config/annotation/EnableWebMvc.java | 4 +- .../WebMvcConfigurationSupport.java | 4 +- .../annotation/WebMvcConfigurationTests.java | 6 +-- 4 files changed, 22 insertions(+), 30 deletions(-) rename org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/{WebMvcConfiguration.java => DelegatingWebMvcConfiguration.java} (55%) diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfiguration.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.java similarity index 55% rename from org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfiguration.java rename to org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.java index e87b8ced3ad..59bc12d4f7e 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfiguration.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.java @@ -25,22 +25,15 @@ import org.springframework.http.converter.HttpMessageConverter; import org.springframework.validation.Validator; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.HandlerMethodReturnValueHandler; -import org.springframework.web.servlet.DispatcherServlet; import org.springframework.web.servlet.HandlerExceptionResolver; /** - * Provides default configuration for Spring MVC applications by registering Spring MVC infrastructure components - * to be detected by the {@link DispatcherServlet}. This class is imported whenever @{@link EnableWebMvc} is - * added to an @{@link Configuration} class. + * A variant of {@link WebMvcConfigurationSupport} that delegates to one or more registered {@link WebMvcConfigurer} + * implementations allowing each of them to customize the default Spring MVC configuration. * - *

See the base class {@link WebMvcConfigurationSupport} for a list of registered instances. This class is closed - * for extension. However, the configuration it provides can be customized by having your @{@link Configuration} - * class implement {@link WebMvcConfigurer} or more conveniently extend from {@link WebMvcConfigurerAdapter}. + *

This class is automatically imported when @{@link EnableWebMvc} is used on an @{@link Configuration} class. + * In turn it detects all implementations of {@link WebMvcConfigurer} via autowiring and in turn delegates to them. * - *

This class will detect your @{@link Configuration} class and any other @{@link Configuration} classes that - * implement {@link WebMvcConfigurer} via autowiring and will allow each of them to participate in the process - * of configuring Spring MVC through the configuration callbacks defined in {@link WebMvcConfigurer}. - * * @see EnableWebMvc * @see WebMvcConfigurer * @@ -48,7 +41,7 @@ import org.springframework.web.servlet.HandlerExceptionResolver; * @since 3.1 */ @Configuration -class WebMvcConfiguration extends WebMvcConfigurationSupport { +public class DelegatingWebMvcConfiguration extends WebMvcConfigurationSupport { private final WebMvcConfigurerComposite configurers = new WebMvcConfigurerComposite(); @@ -61,53 +54,52 @@ class WebMvcConfiguration extends WebMvcConfigurationSupport { } @Override - protected void configureInterceptors(InterceptorConfigurer configurer) { + protected final void configureInterceptors(InterceptorConfigurer configurer) { configurers.configureInterceptors(configurer); } @Override - protected void configureViewControllers(ViewControllerConfigurer configurer) { + protected final void configureViewControllers(ViewControllerConfigurer configurer) { configurers.configureViewControllers(configurer); } @Override - protected void configureResourceHandling(ResourceConfigurer configurer) { + protected final void configureResourceHandling(ResourceConfigurer configurer) { configurers.configureResourceHandling(configurer); } @Override - protected void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { + protected final void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { configurers.configureDefaultServletHandling(configurer); } @Override - protected void addArgumentResolvers(List argumentResolvers) { + protected final void addArgumentResolvers(List argumentResolvers) { configurers.addArgumentResolvers(argumentResolvers); } @Override - protected void addReturnValueHandlers(List returnValueHandlers) { + protected final void addReturnValueHandlers(List returnValueHandlers) { configurers.addReturnValueHandlers(returnValueHandlers); } @Override - protected void configureMessageConverters(List> converters) { + protected final void configureMessageConverters(List> converters) { configurers.configureMessageConverters(converters); } - @Override - protected void addFormatters(FormatterRegistry registry) { + protected final void addFormatters(FormatterRegistry registry) { configurers.addFormatters(registry); } @Override - protected Validator getValidator() { + protected final Validator getValidator() { return configurers.getValidator(); } @Override - protected void configureHandlerExceptionResolvers(List exceptionResolvers) { + protected final void configureHandlerExceptionResolvers(List exceptionResolvers) { configurers.configureHandlerExceptionResolvers(exceptionResolvers); } diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/EnableWebMvc.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/EnableWebMvc.java index f87e049ec19..92794b627c1 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/EnableWebMvc.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/EnableWebMvc.java @@ -25,7 +25,7 @@ import org.springframework.web.servlet.DispatcherServlet; /** * Enables default Spring MVC configuration and registers Spring MVC infrastructure components expected by the * {@link DispatcherServlet}. Add this annotation to an application @{@link Configuration} class. It will in - * turn import the @{@link Configuration} class {@link WebMvcConfiguration}, which provides default Spring MVC + * turn import the @{@link Configuration} class {@link DelegatingWebMvcConfiguration}, which provides default Spring MVC * configuration. *

  * @Configuration
@@ -76,6 +76,6 @@ import org.springframework.web.servlet.DispatcherServlet;
 @Retention(RetentionPolicy.RUNTIME)
 @Target(ElementType.TYPE)
 @Documented
-@Import(WebMvcConfiguration.class)
+@Import(DelegatingWebMvcConfiguration.class)
 public @interface EnableWebMvc {
 }
diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java
index dc3988d9d70..2fe02419360 100644
--- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java
+++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java
@@ -265,7 +265,7 @@ public abstract class WebMvcConfigurationSupport implements ApplicationContextAw
 		ConfigurableWebBindingInitializer webBindingInitializer = new ConfigurableWebBindingInitializer();
 		webBindingInitializer.setConversionService(mvcConversionService());
 		webBindingInitializer.setValidator(mvcValidator());
-		extendWebBindingInitializer(webBindingInitializer);
+		configureWebBindingInitializer(webBindingInitializer);
 		
 		List argumentResolvers = new ArrayList();
 		addArgumentResolvers(argumentResolvers);
@@ -285,7 +285,7 @@ public abstract class WebMvcConfigurationSupport implements ApplicationContextAw
 	 * Override this method to customize the {@link ConfigurableWebBindingInitializer} the 
 	 * {@link RequestMappingHandlerAdapter} is configured with.
 	 */
-	protected void extendWebBindingInitializer(ConfigurableWebBindingInitializer webBindingInitializer) {
+	protected void configureWebBindingInitializer(ConfigurableWebBindingInitializer webBindingInitializer) {
 	}
 
 	/**
diff --git a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationTests.java b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationTests.java
index 18e8693cb79..130342b24f4 100644
--- a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationTests.java
+++ b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationTests.java
@@ -63,14 +63,14 @@ import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolv
  */
 public class WebMvcConfigurationTests {
 
-	private WebMvcConfiguration mvcConfiguration;
+	private DelegatingWebMvcConfiguration mvcConfiguration;
 
 	private WebMvcConfigurer configurer;
 
 	@Before
 	public void setUp() {
 		configurer = EasyMock.createMock(WebMvcConfigurer.class);
-		mvcConfiguration = new WebMvcConfiguration();
+		mvcConfiguration = new DelegatingWebMvcConfiguration();
 	}
 
 	@Test
@@ -114,7 +114,7 @@ public class WebMvcConfigurationTests {
 				converters.add(new StringHttpMessageConverter());
 			}
 		});
-		mvcConfiguration = new WebMvcConfiguration();
+		mvcConfiguration = new DelegatingWebMvcConfiguration();
 		mvcConfiguration.setConfigurers(configurers);
 		
 		adapter = mvcConfiguration.requestMappingHandlerAdapter();