SPR-8430 Rename WebMvcConfiguration to DelegatingWebMvcConfiguration, make it public and make delegation methods final

This commit is contained in:
Rossen Stoyanchev 2011-06-13 12:20:25 +00:00
parent 25e2537c17
commit 883ac319bc
4 changed files with 22 additions and 30 deletions

View File

@ -25,21 +25,14 @@ 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.
*
* <p>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}.
*
* <p>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}.
* <p>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.
*
* @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<HandlerMethodArgumentResolver> argumentResolvers) {
protected final void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
configurers.addArgumentResolvers(argumentResolvers);
}
@Override
protected void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) {
protected final void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) {
configurers.addReturnValueHandlers(returnValueHandlers);
}
@Override
protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
protected final void configureMessageConverters(List<HttpMessageConverter<?>> 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<HandlerExceptionResolver> exceptionResolvers) {
protected final void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
configurers.configureHandlerExceptionResolvers(exceptionResolvers);
}

View File

@ -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.
* <pre class="code">
* &#064;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 {
}

View File

@ -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<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<HandlerMethodArgumentResolver>();
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) {
}
/**

View File

@ -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();