我一直在使用WebMvcConfigurerAdapter。由於我無法使用方法getInterceptors()獲取所有註冊的攔截器,因此我切換到了WebMvcConfigurationSupport,它有很多默認註冊的Spring Bean,如ContentNegotiationManager,ExceptionHandlerExceptionResolver usw.註釋@EnableSpringDataWebSupport不適用於WebMvcConfigurationSupport?
現在我已經意識到,非常方便的DomainClassConverter(它通過使用CrudRepository將域類ID轉換爲域類對象)並未默認註冊,儘管我在WebConfig類上使用了註釋@EnableSpringDataWebSupport。
當我像這樣明確定義這個bean時,它就起作用了。
@EnableSpringDataWebSupport
@Configuration
public class WebConfig extends WebMvcConfigurationSupport {
@Bean
public DomainClassConverter<?> domainClassConverter() {
return new DomainClassConverter<FormattingConversionService>(mvcConversionService());
}
}
但是爲什麼EnableSpringDataWebSupport不能與WebMvcConfigurationSupport一起使用?