The type WebMvcConfigurerAdapter is deprecated

前端 未结 4 787
灰色年华
灰色年华 2020-12-04 08:10

I just migrate to spring mvc version 5.0.1.RELEASE but suddenly in eclipse STS WebMvcConfigurerAdapter is marked as deprecated

public class MvcC         


        
4条回答
  •  庸人自扰
    2020-12-04 08:46

    I have been working on Swagger equivalent documentation library called Springfox nowadays and I found that in the Spring 5.0.8 (running at present), interface WebMvcConfigurer has been implemented by class WebMvcConfigurationSupport class which we can directly extend.

    import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
    
    public class WebConfig extends WebMvcConfigurationSupport { }
    

    And this is how I have used it for setting my resource handling mechanism as follows -

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
    
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
    

提交回复
热议问题