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扩展而来。

如果您重写配置类中的单个回调函数,您可能需要调用超类的回调函数以确保所有处理都正确。

相关问题