【问题标题】:The annotation @EnableSpringDataWebSupport does not work with WebMvcConfigurationSupport?注解@EnableSpringDataWebSupport 不支持WebMvcConfigurationSupport?
【发布时间】:2014-11-23 11:09:46
【问题描述】:

我使用 WebMvcConfigurerAdapter 已经有一段时间了。由于我无法使用 getInterceptors() 方法获取所有已注册的拦截器,因此我已切换到 WebMvcConfigurationSupport,它具有许多默认注册的 Spring Bean,例如 ContentNegotiationManager、ExceptionHandlerExceptionResolver usw。

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

当我像这样明确定义这个 bean 时,它就可以工作了。

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

但是为什么 EnableSpringDataWebSupport 不能与 WebMvcConfigurationSupport 一起使用呢?

【问题讨论】:

    标签: spring spring-mvc spring-java-config spring-data-commons


    【解决方案1】:

    看起来像扩展WebMvcConfigurationSupport 的配置类直接受到SPR-10565 的影响。至少对我而言,解决方案是改为从DelegatingWebMvcConfiguration 扩展。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-09
      • 2020-02-03
      • 2021-08-31
      相关资源
      最近更新 更多