|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2015 the original author or authors. |
|
|
|
* Copyright 2002-2016 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -17,6 +17,7 @@ |
|
|
|
package org.springframework.web.servlet.config.annotation; |
|
|
|
package org.springframework.web.servlet.config.annotation; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Locale; |
|
|
|
import java.util.Locale; |
|
|
|
@ -229,6 +230,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv |
|
|
|
return this.servletContext; |
|
|
|
return this.servletContext; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return a {@link RequestMappingHandlerMapping} ordered at 0 for mapping |
|
|
|
* Return a {@link RequestMappingHandlerMapping} ordered at 0 for mapping |
|
|
|
* requests to annotated controllers. |
|
|
|
* requests to annotated controllers. |
|
|
|
@ -251,18 +253,20 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv |
|
|
|
if (configurer.isUseTrailingSlashMatch() != null) { |
|
|
|
if (configurer.isUseTrailingSlashMatch() != null) { |
|
|
|
handlerMapping.setUseTrailingSlashMatch(configurer.isUseTrailingSlashMatch()); |
|
|
|
handlerMapping.setUseTrailingSlashMatch(configurer.isUseTrailingSlashMatch()); |
|
|
|
} |
|
|
|
} |
|
|
|
if (configurer.getPathMatcher() != null) { |
|
|
|
UrlPathHelper pathHelper = configurer.getUrlPathHelper(); |
|
|
|
handlerMapping.setPathMatcher(configurer.getPathMatcher()); |
|
|
|
if (pathHelper != null) { |
|
|
|
|
|
|
|
handlerMapping.setUrlPathHelper(pathHelper); |
|
|
|
} |
|
|
|
} |
|
|
|
if (configurer.getUrlPathHelper() != null) { |
|
|
|
PathMatcher pathMatcher = configurer.getPathMatcher(); |
|
|
|
handlerMapping.setUrlPathHelper(configurer.getUrlPathHelper()); |
|
|
|
if (pathMatcher != null) { |
|
|
|
|
|
|
|
handlerMapping.setPathMatcher(pathMatcher); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return handlerMapping; |
|
|
|
return handlerMapping; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Protected method for plugging in a custom sub-class of |
|
|
|
* Protected method for plugging in a custom subclass of |
|
|
|
* {@link RequestMappingHandlerMapping}. |
|
|
|
* {@link RequestMappingHandlerMapping}. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected RequestMappingHandlerMapping createRequestMappingHandlerMapping() { |
|
|
|
protected RequestMappingHandlerMapping createRequestMappingHandlerMapping() { |
|
|
|
@ -335,7 +339,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected Map<String, MediaType> getDefaultMediaTypes() { |
|
|
|
protected Map<String, MediaType> getDefaultMediaTypes() { |
|
|
|
Map<String, MediaType> map = new HashMap<String, MediaType>(); |
|
|
|
Map<String, MediaType> map = new HashMap<String, MediaType>(4); |
|
|
|
if (romePresent) { |
|
|
|
if (romePresent) { |
|
|
|
map.put("atom", MediaType.APPLICATION_ATOM_XML); |
|
|
|
map.put("atom", MediaType.APPLICATION_ATOM_XML); |
|
|
|
map.put("rss", MediaType.valueOf("application/rss+xml")); |
|
|
|
map.put("rss", MediaType.valueOf("application/rss+xml")); |
|
|
|
@ -488,18 +492,14 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv |
|
|
|
adapter.setCustomReturnValueHandlers(returnValueHandlers); |
|
|
|
adapter.setCustomReturnValueHandlers(returnValueHandlers); |
|
|
|
|
|
|
|
|
|
|
|
if (jackson2Present) { |
|
|
|
if (jackson2Present) { |
|
|
|
List<RequestBodyAdvice> requestBodyAdvices = new ArrayList<RequestBodyAdvice>(); |
|
|
|
adapter.setRequestBodyAdvice( |
|
|
|
requestBodyAdvices.add(new JsonViewRequestBodyAdvice()); |
|
|
|
Collections.<RequestBodyAdvice>singletonList(new JsonViewRequestBodyAdvice())); |
|
|
|
adapter.setRequestBodyAdvice(requestBodyAdvices); |
|
|
|
adapter.setResponseBodyAdvice( |
|
|
|
|
|
|
|
Collections.<ResponseBodyAdvice<?>>singletonList(new JsonViewResponseBodyAdvice())); |
|
|
|
List<ResponseBodyAdvice<?>> responseBodyAdvices = new ArrayList<ResponseBodyAdvice<?>>(); |
|
|
|
|
|
|
|
responseBodyAdvices.add(new JsonViewResponseBodyAdvice()); |
|
|
|
|
|
|
|
adapter.setResponseBodyAdvice(responseBodyAdvices); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
AsyncSupportConfigurer configurer = new AsyncSupportConfigurer(); |
|
|
|
AsyncSupportConfigurer configurer = new AsyncSupportConfigurer(); |
|
|
|
configureAsyncSupport(configurer); |
|
|
|
configureAsyncSupport(configurer); |
|
|
|
|
|
|
|
|
|
|
|
if (configurer.getTaskExecutor() != null) { |
|
|
|
if (configurer.getTaskExecutor() != null) { |
|
|
|
adapter.setTaskExecutor(configurer.getTaskExecutor()); |
|
|
|
adapter.setTaskExecutor(configurer.getTaskExecutor()); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -524,6 +524,20 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv |
|
|
|
return initializer; |
|
|
|
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 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected void configureAsyncSupport(AsyncSupportConfigurer configurer) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return a {@link FormattingConversionService} for use with annotated |
|
|
|
* Return a {@link FormattingConversionService} for use with annotated |
|
|
|
* controller methods and the {@code spring:eval} JSP tag. |
|
|
|
* controller methods and the {@code spring:eval} JSP tag. |
|
|
|
@ -536,6 +550,12 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv |
|
|
|
return conversionService; |
|
|
|
return conversionService; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Override this method to add custom {@link Converter}s and {@link Formatter}s. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected void addFormatters(FormatterRegistry registry) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return a global {@link Validator} instance for example for validating |
|
|
|
* Return a global {@link Validator} instance for example for validating |
|
|
|
* {@code @ModelAttribute} and {@code @RequestBody} method arguments. |
|
|
|
* {@code @ModelAttribute} and {@code @RequestBody} method arguments. |
|
|
|
@ -560,7 +580,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv |
|
|
|
catch (LinkageError ex) { |
|
|
|
catch (LinkageError ex) { |
|
|
|
throw new BeanInitializationException("Could not load default validator class", ex); |
|
|
|
throw new BeanInitializationException("Could not load default validator class", ex); |
|
|
|
} |
|
|
|
} |
|
|
|
validator = (Validator) BeanUtils.instantiate(clazz); |
|
|
|
validator = (Validator) BeanUtils.instantiateClass(clazz); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
validator = new NoOpValidator(); |
|
|
|
validator = new NoOpValidator(); |
|
|
|
@ -569,6 +589,13 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv |
|
|
|
return validator; |
|
|
|
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 |
|
|
|
* Return a global {@link PathMatcher} instance for path matching |
|
|
|
* patterns in {@link HandlerMapping}s. |
|
|
|
* patterns in {@link HandlerMapping}s. |
|
|
|
@ -595,26 +622,8 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Bean |
|
|
|
@Bean |
|
|
|
public UrlPathHelper mvcUrlPathHelper() { |
|
|
|
public UrlPathHelper mvcUrlPathHelper() { |
|
|
|
if (getPathMatchConfigurer().getUrlPathHelper() != null) { |
|
|
|
UrlPathHelper pathHelper = getPathMatchConfigurer().getUrlPathHelper(); |
|
|
|
return getPathMatchConfigurer().getUrlPathHelper(); |
|
|
|
return (pathHelper != null ? pathHelper : new UrlPathHelper()); |
|
|
|
} |
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -679,6 +688,14 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv |
|
|
|
protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) { |
|
|
|
protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Override this method to extend or modify the list of converters after it |
|
|
|
|
|
|
|
* has been configured. This may be useful for example to allow default |
|
|
|
|
|
|
|
* converters to be registered and then insert a custom converter through |
|
|
|
|
|
|
|
* this method. |
|
|
|
|
|
|
|
* @param converters the list of configured converters to extend. |
|
|
|
|
|
|
|
* @since 4.1.3 |
|
|
|
|
|
|
|
*/ |
|
|
|
protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) { |
|
|
|
protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -719,19 +736,6 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Override this method to add custom {@link Converter}s and {@link Formatter}s. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected void addFormatters(FormatterRegistry registry) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Override this method to configure asynchronous request processing options. |
|
|
|
|
|
|
|
* @see AsyncSupportConfigurer |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void configureAsyncSupport(AsyncSupportConfigurer configurer) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return an instance of {@link CompositeUriComponentsContributor} for use with |
|
|
|
* Return an instance of {@link CompositeUriComponentsContributor} for use with |
|
|
|
* {@link org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder}. |
|
|
|
* {@link org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder}. |
|
|
|
@ -774,11 +778,9 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv |
|
|
|
public HandlerExceptionResolver handlerExceptionResolver() { |
|
|
|
public HandlerExceptionResolver handlerExceptionResolver() { |
|
|
|
List<HandlerExceptionResolver> exceptionResolvers = new ArrayList<HandlerExceptionResolver>(); |
|
|
|
List<HandlerExceptionResolver> exceptionResolvers = new ArrayList<HandlerExceptionResolver>(); |
|
|
|
configureHandlerExceptionResolvers(exceptionResolvers); |
|
|
|
configureHandlerExceptionResolvers(exceptionResolvers); |
|
|
|
|
|
|
|
|
|
|
|
if (exceptionResolvers.isEmpty()) { |
|
|
|
if (exceptionResolvers.isEmpty()) { |
|
|
|
addDefaultHandlerExceptionResolvers(exceptionResolvers); |
|
|
|
addDefaultHandlerExceptionResolvers(exceptionResolvers); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
HandlerExceptionResolverComposite composite = new HandlerExceptionResolverComposite(); |
|
|
|
HandlerExceptionResolverComposite composite = new HandlerExceptionResolverComposite(); |
|
|
|
composite.setOrder(0); |
|
|
|
composite.setOrder(0); |
|
|
|
composite.setExceptionResolvers(exceptionResolvers); |
|
|
|
composite.setExceptionResolvers(exceptionResolvers); |
|
|
|
|