4

我一直在使用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一起使用?

回答

2

它看起來像擴展的配置類WebMvcConfigurationSupport直接遭受SPR-10565。至少對我而言,解決方案是從DelegatingWebMvcConfiguration擴展而來。

如果您重寫配置類中的單個回調函數,您可能需要調用超類的回調函數以確保所有處理都正確。

相關問題