【发布时间】:2014-11-23 11:09:46
【问题描述】:
我使用 WebMvcConfigurerAdapter 已经有一段时间了。由于我无法使用 getInterceptors() 方法获取所有已注册的拦截器,因此我已切换到 WebMvcConfigurationSupport,它具有许多默认注册的 Spring Bean,例如 ContentNegotiationManager、ExceptionHandlerExceptionResolver usw。
现在我意识到,非常方便的 DomainClassConverter(它通过使用 CrudRepository 将域类 ID 转换为域类对象)默认情况下没有注册,尽管我在我的 WebConfig 类上使用了注释 @EnableSpringDataWebSupport。
当我像这样明确定义这个 bean 时,它就可以工作了。
@EnableSpringDataWebSupport
@Configuration
public class WebConfig extends WebMvcConfigurationSupport {
@Bean
public DomainClassConverter<?> domainClassConverter() {
return new DomainClassConverter<FormattingConversionService>(mvcConversionService());
}
}
但是为什么 EnableSpringDataWebSupport 不能与 WebMvcConfigurationSupport 一起使用呢?
【问题讨论】:
标签: spring spring-mvc spring-java-config spring-data-commons