diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java index c9c9be60201..4e08188c435 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java @@ -438,7 +438,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC catch (Throwable ex) { throw new BeanInitializationException("Could not find default validator class", ex); } - validator = (Validator) BeanUtils.instantiate(clazz); + validator = (Validator) BeanUtils.instantiateClass(clazz); } else { validator = new Validator() { 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 6d5ab799626..10cc5bdac0e 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 @@ -17,6 +17,7 @@ package org.springframework.web.servlet.config.annotation; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -233,6 +234,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv return this.servletContext; } + /** * Return a {@link RequestMappingHandlerMapping} ordered at 0 for mapping * requests to annotated controllers. @@ -255,11 +257,13 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv if (configurer.isUseTrailingSlashMatch() != null) { handlerMapping.setUseTrailingSlashMatch(configurer.isUseTrailingSlashMatch()); } - if (configurer.getPathMatcher() != null) { - handlerMapping.setPathMatcher(configurer.getPathMatcher()); + UrlPathHelper pathHelper = configurer.getUrlPathHelper(); + if (pathHelper != null) { + handlerMapping.setUrlPathHelper(pathHelper); } - if (configurer.getUrlPathHelper() != null) { - handlerMapping.setUrlPathHelper(configurer.getUrlPathHelper()); + PathMatcher pathMatcher = configurer.getPathMatcher(); + if (pathMatcher != null) { + handlerMapping.setPathMatcher(pathMatcher); } return handlerMapping; @@ -339,7 +343,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv } protected Map getDefaultMediaTypes() { - Map map = new HashMap(); + Map map = new HashMap(4); if (romePresent) { map.put("atom", MediaType.APPLICATION_ATOM_XML); map.put("rss", MediaType.valueOf("application/rss+xml")); @@ -487,18 +491,14 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv adapter.setCustomReturnValueHandlers(getReturnValueHandlers()); if (jackson2Present) { - List requestBodyAdvices = new ArrayList(); - requestBodyAdvices.add(new JsonViewRequestBodyAdvice()); - adapter.setRequestBodyAdvice(requestBodyAdvices); - - List> responseBodyAdvices = new ArrayList>(); - responseBodyAdvices.add(new JsonViewResponseBodyAdvice()); - adapter.setResponseBodyAdvice(responseBodyAdvices); + adapter.setRequestBodyAdvice( + Collections.singletonList(new JsonViewRequestBodyAdvice())); + adapter.setResponseBodyAdvice( + Collections.>singletonList(new JsonViewResponseBodyAdvice())); } AsyncSupportConfigurer configurer = new AsyncSupportConfigurer(); configureAsyncSupport(configurer); - if (configurer.getTaskExecutor() != null) { adapter.setTaskExecutor(configurer.getTaskExecutor()); } @@ -531,6 +531,13 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv return initializer; } + /** + * Override this method to provide a custom {@link MessageCodesResolver}. + */ + protected MessageCodesResolver getMessageCodesResolver() { + return null; + } + /** * Override this method to configure asynchronous request processing options. * @see AsyncSupportConfigurer @@ -580,7 +587,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv catch (LinkageError ex) { throw new BeanInitializationException("Could not load default validator class", ex); } - validator = (Validator) BeanUtils.instantiate(clazz); + validator = (Validator) BeanUtils.instantiateClass(clazz); } else { validator = new NoOpValidator(); @@ -589,6 +596,13 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv return validator; } + /** + * Override this method to provide a custom {@link Validator}. + */ + protected Validator getValidator() { + return null; + } + /** * Return a global {@link PathMatcher} instance for path matching * patterns in {@link HandlerMapping}s. @@ -615,26 +629,8 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv */ @Bean public UrlPathHelper mvcUrlPathHelper() { - if (getPathMatchConfigurer().getUrlPathHelper() != null) { - return getPathMatchConfigurer().getUrlPathHelper(); - } - else { - return new UrlPathHelper(); - } - } - - /** - * Override this method to provide a custom {@link Validator}. - */ - protected Validator getValidator() { - return null; - } - - /** - * Override this method to provide a custom {@link MessageCodesResolver}. - */ - protected MessageCodesResolver getMessageCodesResolver() { - return null; + UrlPathHelper pathHelper = getPathMatchConfigurer().getUrlPathHelper(); + return (pathHelper != null ? pathHelper : new UrlPathHelper()); } /** @@ -817,11 +813,9 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv public HandlerExceptionResolver handlerExceptionResolver() { List exceptionResolvers = new ArrayList(); configureHandlerExceptionResolvers(exceptionResolvers); - if (exceptionResolvers.isEmpty()) { addDefaultHandlerExceptionResolvers(exceptionResolvers); } - extendHandlerExceptionResolvers(exceptionResolvers); HandlerExceptionResolverComposite composite = new HandlerExceptionResolverComposite(); composite.setOrder(0); @@ -871,9 +865,8 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv exceptionHandlerResolver.setCustomArgumentResolvers(getArgumentResolvers()); exceptionHandlerResolver.setCustomReturnValueHandlers(getReturnValueHandlers()); if (jackson2Present) { - List> interceptors = new ArrayList>(); - interceptors.add(new JsonViewResponseBodyAdvice()); - exceptionHandlerResolver.setResponseBodyAdvice(interceptors); + exceptionHandlerResolver.setResponseBodyAdvice( + Collections.>singletonList(new JsonViewResponseBodyAdvice())); } exceptionHandlerResolver.setApplicationContext(this.applicationContext); exceptionHandlerResolver.afterPropertiesSet();