@ -17,15 +17,14 @@ package org.springframework.data.web.config;
@@ -17,15 +17,14 @@ package org.springframework.data.web.config;
import java.util.List ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Qualifier ;
import org.springframework.context.ApplicationContext ;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.annotation.Configuration ;
import org.springframework.data.repository.support.DomainClassConverter ;
import org.springframework.data.web.PageableHandlerMethodArgumentResolver ;
import org.springframework.data.web.SortHandlerMethodArgumentResolver ;
import org.springframework.format.FormatterRegistry ;
import org.springframework.format.support.FormattingConversionService ;
import org.springframework.web.method.support.HandlerMethodArgumentResolver ;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter ;
@ -40,11 +39,8 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
@@ -40,11 +39,8 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
@Configuration
class SpringDataWebConfiguration extends WebMvcConfigurerAdapter {
private static final Logger LOGGER = LoggerFactory . getLogger ( SpringDataWebConfiguration . class ) ;
@Autowired ( required = false )
@Qualifier ( "mvcConversionService" )
FormattingConversionService conversionService ;
@Autowired
private ApplicationContext context ;
@Bean
public PageableHandlerMethodArgumentResolver pageableResolver ( ) {
@ -56,18 +52,25 @@ class SpringDataWebConfiguration extends WebMvcConfigurerAdapter {
@@ -56,18 +52,25 @@ class SpringDataWebConfiguration extends WebMvcConfigurerAdapter {
return new SortHandlerMethodArgumentResolver ( ) ;
}
@Bean
public DomainClassConverter < FormattingConversionService > mvcDomainClassConverter ( ) {
/ *
* ( non - Javadoc )
* @see org . springframework . web . servlet . config . annotation . WebMvcConfigurerAdapter # addFormatters ( org . springframework . format . FormatterRegistry )
* /
@Override
public void addFormatters ( FormatterRegistry registry ) {
if ( conversionService = = null ) {
if ( ! ( registry instanceof FormattingConversionService ) ) {
return ;
}
LOGGER . warn ( "No default Spring MVC FormattingConversionService registered! Have you forgotten to "
+ "use @EnableWebMvc or register a configuration class extending WebMvcConfigurationSupport?" ) ;
registerDomainClassConverterFor ( ( FormattingConversionService ) registry ) ;
}
return null ;
}
private void registerDomainClassConverterFor ( FormattingConversionService conversionService ) {
return new DomainClassConverter < FormattingConversionService > ( conversionService ) ;
DomainClassConverter < FormattingConversionService > converter = new DomainClassConverter < FormattingConversionService > (
conversionService ) ;
converter . setApplicationContext ( context ) ;
}
/ *