diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/DefaultServletHandlerConfigurer.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/DefaultServletHandlerConfigurer.java index d4f8f78ace6..e9b713fc7ea 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/DefaultServletHandlerConfigurer.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/DefaultServletHandlerConfigurer.java @@ -34,7 +34,7 @@ import org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler * by the Servlet container's default servlet. * *
It is important the configured handler remains last in the order of all {@link HandlerMapping} instances in - * the Spring MVC web application context. That is is the case if relying on @{@link EnableMvcConfiguration}. + * the Spring MVC web application context. That is is the case if relying on @{@link EnableWebMvc}. * However, if you register your own HandlerMapping instance sure to set its "order" property to a value lower * than that of the {@link DefaultServletHttpRequestHandler}, which is {@link Integer#MAX_VALUE}. * diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/EnableMvcConfiguration.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/EnableWebMvc.java similarity index 79% rename from org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/EnableMvcConfiguration.java rename to org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/EnableWebMvc.java index 705705314f9..e16bd2d91e3 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/EnableMvcConfiguration.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/EnableWebMvc.java @@ -30,28 +30,28 @@ import org.springframework.web.servlet.DispatcherServlet; * in @{@link Controller} classes. *
* @Configuration
- * @EnableMvcConfiguration
+ * @EnableWebMvc
* @ComponentScan(
- * basePackageClasses = { MyMvcConfiguration.class },
+ * basePackageClasses = { MyConfiguration.class },
* excludeFilters = { @Filter(type = FilterType.ANNOTATION, value = Configuration.class) }
* )
- * public class MyMvcConfiguration {
+ * public class MyConfiguration {
*
* }
*
- * To customize the imported configuration you simply implement {@link MvcConfigurer}, or more likely extend - * {@link MvcConfigurerSupport} overriding selected methods only. The most obvious place to do this is - * the @{@link Configuration} class that enabled the Spring MVC configuration via @{@link EnableMvcConfiguration}. - * However any @{@link Configuration} class and more generally any Spring bean can implement {@link MvcConfigurer} + *
To customize the imported configuration you simply implement {@link WebMvcConfigurer}, or more likely extend + * {@link WebMvcConfigurerAdapter} overriding selected methods only. The most obvious place to do this is + * the @{@link Configuration} class that enabled the Spring MVC configuration via @{@link EnableWebMvc}. + * However any @{@link Configuration} class and more generally any Spring bean can implement {@link WebMvcConfigurer} * to be detected and given an opportunity to customize Spring MVC configuration at startup. *
* @Configuration
- * @EnableMvcConfiguration
+ * @EnableWebMvc
* @ComponentScan(
- * basePackageClasses = { MyMvcConfiguration.class },
+ * basePackageClasses = { MyConfiguration.class },
* excludeFilters = { @Filter(type = FilterType.ANNOTATION, value = Configuration.class) }
* )
- * public class MyMvcConfiguration extends MvcConfigurerSupport {
+ * public class MyConfiguration extends WebMvcConfigurerAdapter {
*
* @Override
* public void registerFormatters(FormatterRegistry formatterRegistry) {
@@ -68,8 +68,8 @@ import org.springframework.web.servlet.DispatcherServlet;
* }
*
*
- * @see MvcConfigurer
- * @see MvcConfigurerSupport
+ * @see WebMvcConfigurer
+ * @see WebMvcConfigurerAdapter
*
* @author Dave Syer
* @author Rossen Stoyanchev
@@ -78,6 +78,6 @@ import org.springframework.web.servlet.DispatcherServlet;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
-@Import(MvcConfiguration.class)
-public @interface EnableMvcConfiguration {
+@Import(WebMvcConfiguration.class)
+public @interface EnableWebMvc {
}
diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorConfigurer.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorConfigurer.java
index e52c7b4e2a7..0cb67fb3bae 100644
--- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorConfigurer.java
+++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorConfigurer.java
@@ -24,7 +24,6 @@ import org.springframework.web.context.request.WebRequestInterceptor;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.handler.MappedInterceptor;
-import org.springframework.web.servlet.handler.MappedInterceptors;
import org.springframework.web.servlet.handler.WebRequestHandlerInterceptorAdapter;
/**
@@ -117,10 +116,10 @@ public class InterceptorConfigurer {
}
/**
- * Returns a {@link MappedInterceptors} instance with all registered interceptors.
+ * Returns all registered interceptors.
*/
- protected MappedInterceptors getMappedInterceptors() {
- return new MappedInterceptors(mappedInterceptors.toArray(new MappedInterceptor[mappedInterceptors.size()]));
+ protected MappedInterceptor[] getInterceptors() {
+ return mappedInterceptors.toArray(new MappedInterceptor[mappedInterceptors.size()]);
}
}
diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/MvcConfiguration.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfiguration.java
similarity index 81%
rename from org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/MvcConfiguration.java
rename to org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfiguration.java
index 655cf7185ae..fe38c31a3dd 100644
--- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/MvcConfiguration.java
+++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfiguration.java
@@ -58,6 +58,7 @@ import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping;
import org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor;
import org.springframework.web.servlet.handler.HandlerExceptionResolverComposite;
+import org.springframework.web.servlet.handler.MappedInterceptor;
import org.springframework.web.servlet.handler.MappedInterceptors;
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
import org.springframework.web.servlet.mvc.Controller;
@@ -72,10 +73,10 @@ import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolv
/**
* Provides default configuration for Spring MVC applications. Registers Spring MVC infrastructure components to be
* detected by the {@link DispatcherServlet}. Further below is a list of registered instances. This configuration is
- * enabled through the {@link EnableMvcConfiguration} annotation.
+ * enabled through the {@link EnableWebMvc} annotation.
*
* A number of options are available for customizing the default configuration provided by this class. - * See {@link EnableMvcConfiguration} and {@link MvcConfigurer} for details. + * See {@link EnableWebMvc} and {@link WebMvcConfigurer} for details. * *
Registers these handler mappings: *
Note: that the SimpleUrlHandlerMapping instances above will have empty URL maps and - * hence no effect until explicitly configured via {@link MvcConfigurer}. + * hence no effect until explicitly configured via {@link WebMvcConfigurer}. * *
Registers these handler adapters: *
Implementations of this interface will find it convenient to extend {@link MvcConfigurerSupport} that + *
Implementations of this interface will find it convenient to extend {@link WebMvcConfigurerAdapter} that
* provides default method implementations and allows overriding only methods of interest.
*
* @author Rossen Stoyanchev
@@ -49,17 +49,18 @@ import com.sun.corba.se.impl.presentation.rmi.ExceptionHandler;
* @author David Syer
* @since 3.1
*/
-public interface MvcConfigurer {
+public interface WebMvcConfigurer {
/**
- * Register application-specific {@link Converter}s and {@link Formatter}s for use in Spring MVC.
+ * Add {@link Converter}s and {@link Formatter}s in addition to the ones registered by default.
*/
- void registerFormatters(FormatterRegistry formatterRegistry);
+ void addFormatters(FormatterRegistry formatterRegistry);
/**
- * Customize the list of {@link HttpMessageConverter}s to use when resolving method arguments or handling
- * return values from @{@link RequestMapping} and @{@link ExceptionHandler} methods.
- * @param converters the list of converters, initially populated with the default set of converters
+ * Configure the list of {@link HttpMessageConverter}s to use when resolving method arguments or handling
+ * return values in @{@link RequestMapping} and @{@link ExceptionHandler} methods.
+ * Specifying custom converters overrides the converters registered by default.
+ * @param converters a list to add message converters to
*/
void configureMessageConverters(List Generally custom argument resolvers are invoked first. However this excludes default argument resolvers that
+ * rely on the presence of annotations (e.g. {@code @RequestParameter}, {@code @PathVariable}, etc.). Those
+ * argument resolvers are not customizable without configuring RequestMappingHandlerAdapter directly.
* @param argumentResolvers the list of custom converters, initially empty
*/
- void addCustomArgumentResolvers(List Generally custom return value handlers are invoked first. However this excludes default return value handlers
+ * that rely on the presence of annotations (e.g. {@code @ResponseBody}, {@code @ModelAttribute}, etc.). Those
+ * handlers are not customizable without configuring RequestMappingHandlerAdapter directly.
* @param returnValueHandlers the list of custom handlers, initially empty
*/
- void addCustomReturnValueHandlers(List This implementation is empty.
*/
- public void registerFormatters(FormatterRegistry formatterRegistry) {
+ public void addFormatters(FormatterRegistry formatterRegistry) {
}
/**
@@ -47,13 +48,6 @@ public abstract class MvcConfigurerSupport implements MvcConfigurer {
public void configureMessageConverters(List This implementation is empty.
- */
- public void configureValidator(Validator validator) {
- }
-
/**
* {@inheritDoc}
* This implementation returns {@code null}
@@ -66,7 +60,14 @@ public abstract class MvcConfigurerSupport implements MvcConfigurer {
* {@inheritDoc}
* This implementation is empty.
*/
- public void addCustomArgumentResolvers(List This implementation is empty.
+ */
+ public void addReturnValueHandlers(List This implementation is empty.
*/
- public void addInterceptors(InterceptorConfigurer interceptorConfigurer) {
+ public void configureInterceptors(InterceptorConfigurer interceptorConfigurer) {
}
/**
* {@inheritDoc}
* This implementation is empty.
*/
- public void addViewControllers(ViewControllerConfigurer viewControllerConfigurer) {
+ public void configureViewControllers(ViewControllerConfigurer viewControllerConfigurer) {
}
/**
diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/MvcConfigurerComposite.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurerComposite.java
similarity index 59%
rename from org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/MvcConfigurerComposite.java
rename to org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurerComposite.java
index 1d90bdf9ee2..efc09b3ae1e 100644
--- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/MvcConfigurerComposite.java
+++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurerComposite.java
@@ -29,78 +29,78 @@ import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.HandlerExceptionResolver;
/**
- * An {@link MvcConfigurer} implementation that delegates to other {@link MvcConfigurer} instances.
+ * An {@link WebMvcConfigurer} implementation that delegates to other {@link WebMvcConfigurer} instances.
*
* @author Rossen Stoyanchev
* @since 3.1
*/
-class MvcConfigurerComposite implements MvcConfigurer {
+class WebMvcConfigurerComposite implements WebMvcConfigurer {
- private final List>> converters = new Capture
>>();
expect(configurer.getValidator()).andReturn(null);
- configurer.registerFormatters(capture(conversionService));
- configurer.addCustomArgumentResolvers(capture(resolvers));
- configurer.addCustomReturnValueHandlers(capture(handlers));
+ configurer.addFormatters(capture(conversionService));
+ configurer.addArgumentResolvers(capture(resolvers));
+ configurer.addReturnValueHandlers(capture(handlers));
configurer.configureMessageConverters(capture(converters));
replay(configurer);
+ mvcConfiguration.setConfigurers(Arrays.asList(configurer));
RequestMappingHandlerAdapter adapter = mvcConfiguration.requestMappingHandlerAdapter();
ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
@@ -89,11 +101,30 @@ public class MvcConfigurationTests {
verify(configurer);
}
+ @Test
+ public void configureMessageConverters() {
+ RequestMappingHandlerAdapter adapter = mvcConfiguration.requestMappingHandlerAdapter();
+ assertTrue("There should be at least two default converters ", adapter.getMessageConverters().size() > 1);
+
+ List