Skip to content

Commit 73b9d60

Browse files
committed
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.
1 parent 16c3c15 commit 73b9d60

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717

1818
import java.util.List;
1919

20-
import org.slf4j.Logger;
21-
import org.slf4j.LoggerFactory;
2220
import org.springframework.beans.factory.annotation.Autowired;
23-
import org.springframework.beans.factory.annotation.Qualifier;
21+
import org.springframework.context.ApplicationContext;
2422
import org.springframework.context.annotation.Bean;
2523
import org.springframework.context.annotation.Configuration;
2624
import org.springframework.data.repository.support.DomainClassConverter;
2725
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
2826
import org.springframework.data.web.SortHandlerMethodArgumentResolver;
27+
import org.springframework.format.FormatterRegistry;
2928
import org.springframework.format.support.FormattingConversionService;
3029
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
3130
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@@ -40,11 +39,8 @@
4039
@Configuration
4140
class SpringDataWebConfiguration extends WebMvcConfigurerAdapter {
4241

43-
private static final Logger LOGGER = LoggerFactory.getLogger(SpringDataWebConfiguration.class);
44-
45-
@Autowired(required = false)
46-
@Qualifier("mvcConversionService")
47-
FormattingConversionService conversionService;
42+
@Autowired
43+
private ApplicationContext context;
4844

4945
@Bean
5046
public PageableHandlerMethodArgumentResolver pageableResolver() {
@@ -56,18 +52,25 @@ public SortHandlerMethodArgumentResolver sortResolver() {
5652
return new SortHandlerMethodArgumentResolver();
5753
}
5854

59-
@Bean
60-
public DomainClassConverter<FormattingConversionService> mvcDomainClassConverter() {
55+
/*
56+
* (non-Javadoc)
57+
* @see org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter#addFormatters(org.springframework.format.FormatterRegistry)
58+
*/
59+
@Override
60+
public void addFormatters(FormatterRegistry registry) {
6161

62-
if (conversionService == null) {
62+
if (!(registry instanceof FormattingConversionService)) {
63+
return;
64+
}
6365

64-
LOGGER.warn("No default Spring MVC FormattingConversionService registered! Have you forgotten to "
65-
+ "use @EnableWebMvc or register a configuration class extending WebMvcConfigurationSupport?");
66+
registerDomainClassConverterFor((FormattingConversionService) registry);
67+
}
6668

67-
return null;
68-
}
69+
private void registerDomainClassConverterFor(FormattingConversionService conversionService) {
6970

70-
return new DomainClassConverter<FormattingConversionService>(conversionService);
71+
DomainClassConverter<FormattingConversionService> converter = new DomainClassConverter<FormattingConversionService>(
72+
conversionService);
73+
converter.setApplicationContext(context);
7174
}
7275

7376
/*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void registersBasicBeanDefinitions() throws Exception {
6464
ApplicationContext context = WebTestUtils.createApplicationContext(SampleConfig.class);
6565
List<String> names = Arrays.asList(context.getBeanDefinitionNames());
6666

67-
assertThat(names, hasItems("pageableResolver", "sortResolver", "mvcDomainClassConverter"));
67+
assertThat(names, hasItems("pageableResolver", "sortResolver"));
6868

6969
assertResolversRegistered(context, SortHandlerMethodArgumentResolver.class,
7070
PageableHandlerMethodArgumentResolver.class);

0 commit comments

Comments
 (0)