akc*_*soy 5 spring spring-mvc spring-java-config spring-data-commons
我已经使用WebMvcConfigurerAdapter已有一段时间了。由于无法使用getInterceptors()方法获取所有已注册的拦截器,因此我切换到了WebMvcConfigurationSupport,它具有许多默认的已注册Spring Bean,例如ContentNegotiationManager,ExceptionHandlerExceptionResolverusw。
现在,我已经意识到,尽管我在WebConfig类上使用了@EnableSpringDataWebSupport批注,但非常方便的DomainClassConverter(使用CrudRepository将域类ID转换为域类对象)并未默认注册。
当我像这样显式定义此bean时,它就会起作用。
@EnableSpringDataWebSupport
@Configuration
public class WebConfig extends WebMvcConfigurationSupport {
@Bean
public DomainClassConverter<?> domainClassConverter() {
return new DomainClassConverter<FormattingConversionService>(mvcConversionService());
}
}
Run Code Online (Sandbox Code Playgroud)
但是,为什么EnableSpringDataWebSupport无法与WebMvcConfigurationSupport一起使用?
| 归档时间: |
|
| 查看次数: |
2646 次 |
| 最近记录: |