DATACMNS-330, DATACMNS-331 - More improvements on web configuration.

Reverting the registration of the DomainClassConverter as a Spring bean an prefer direct registration against the FormatterRegistry handed into addFormatters(…) of WebMvcConvfigurerAdapter. Otherwise we run into CGLib issues while enhancing the config classes.
This commit is contained in:
Oliver Gierke
2013-05-22 10:18:26 +02:00
parent 16c3c15204
commit 73b9d60be5
2 changed files with 21 additions and 18 deletions

View File

@@ -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
@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 {
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) {
LOGGER.warn("No default Spring MVC FormattingConversionService registered! Have you forgotten to "
+ "use @EnableWebMvc or register a configuration class extending WebMvcConfigurationSupport?");
return null;
if (!(registry instanceof FormattingConversionService)) {
return;
}
return new DomainClassConverter<FormattingConversionService>(conversionService);
registerDomainClassConverterFor((FormattingConversionService) registry);
}
private void registerDomainClassConverterFor(FormattingConversionService conversionService) {
DomainClassConverter<FormattingConversionService> converter = new DomainClassConverter<FormattingConversionService>(
conversionService);
converter.setApplicationContext(context);
}
/*