Browse Source

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.
pull/29/merge
Oliver Gierke 13 years ago
parent
commit
73b9d60be5
  1. 35
      src/main/java/org/springframework/data/web/config/SpringDataWebConfiguration.java
  2. 2
      src/test/java/org/springframework/data/web/config/EnableSpringDataWebSupportIntegrationTests.java

35
src/main/java/org/springframework/data/web/config/SpringDataWebConfiguration.java

@ -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);
}
/*

2
src/test/java/org/springframework/data/web/config/EnableSpringDataWebSupportIntegrationTests.java

@ -64,7 +64,7 @@ public class EnableSpringDataWebSupportIntegrationTests { @@ -64,7 +64,7 @@ public class EnableSpringDataWebSupportIntegrationTests {
ApplicationContext context = WebTestUtils.createApplicationContext(SampleConfig.class);
List<String> names = Arrays.asList(context.getBeanDefinitionNames());
assertThat(names, hasItems("pageableResolver", "sortResolver", "mvcDomainClassConverter"));
assertThat(names, hasItems("pageableResolver", "sortResolver"));
assertResolversRegistered(context, SortHandlerMethodArgumentResolver.class,
PageableHandlerMethodArgumentResolver.class);

Loading…
Cancel
Save