@EnableSpringDataWebSupport注解无法与WebMvcConfigurationSupport一起使用?

5

我之前一直在使用WebMvcConfigurerAdapter。由于无法通过getInterceptors()方法获取所有已注册的拦截器,因此我转而使用了WebMvcConfigurationSupport,它具有很多默认注册的Spring Bean,如ContentNegotiationManager、ExceptionHandlerExceptionResolver等。

现在我意识到,默认情况下并没有注册非常方便的DomainClassConverter(它通过使用CrudRepository将域类id转换为域类对象),尽管我在WebConfig类上使用了@EnableSpringDataWebSupport注解。

当我像这样显式地定义这个bean时,它就可以正常工作。

@EnableSpringDataWebSupport
@Configuration
public class WebConfig extends WebMvcConfigurationSupport {
    @Bean
    public DomainClassConverter<?> domainClassConverter() {
        return new DomainClassConverter<FormattingConversionService>(mvcConversionService());
    }
}

为什么EnableSpringDataWebSupport与WebMvcConfigurationSupport不兼容?
1个回答

3
看起来直接扩展WebMvcConfigurationSupport的配置类会遭受SPR-10565问题。解决方案,至少对我而言,是从DelegatingWebMvcConfiguration扩展。

如果您正在覆盖配置类中的单个回调,则可能还希望调用超类的回调实现,以确保正确处理所有内容。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接