Equivalent of mvc:default-servlet-handler in Spring annotation-based configuration?

后端 未结 4 2397
野趣味
野趣味 2021-02-19 00:45

Is it possible to have the equivalent of defined in an AnnotationConfig(Web)ApplicationContext? Right now I have:<

4条回答
  •  醉酒成梦
    2021-02-19 00:59

    After digging a bit deeper, I found out that this is a known problem and is addressed by annotation features in the upcoming Spring 3.1.

    I solved my problem with the following code:

    @Configuration
    @Import(FeatureConfig.class)
    class AppConfig {
       ...
    }
    
    @FeatureConfiguration
    class FeatureConfig {
      @Feature
      public MvcDefaultServletHandler defaultHandler() {
        return new MvcDefaultServletHandler();
      }
    }
    

    This does require using the milestone version of spring, though, but it seems to be the cleanest and preferred way of handling this.

提交回复
热议问题