首页 > 编程语言 > 详细

SpringBoot2继承了WebMvcConfigurationSupport后,WebMvcAutoConfiguration自动配置失效

时间:2019-01-22 19:02:13      阅读:565      评论:0      收藏:0      [点我收藏+]

SpringBoot1继承的WebMvcConfigurerAdapter,在 2 中废弃了

SpringBoot2继承了WebMvcConfigurationSupport 后,WebMvcAutoConfiguration自动配置失效,需要全部手动配置

@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
    /**
     * 静态资源映射
     */
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        // addResourceHandler 设置访问路径前缀,addResourceLocations 设置资源路径
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");

    }

    /**
     * 页面跳转
     */
    @Override
    protected void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("index").setViewName("index");
    }

    /**
     * 拦截器配置
     */
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/goLogin", "/login");
    }

    /**
     * 编码配置
     */
    @Override
    protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        super.configureMessageConverters(converters);
        converters.add(new StringHttpMessageConverter(Charset.forName("UTF-8")));
    }
}

 

SpringBoot2继承了WebMvcConfigurationSupport后,WebMvcAutoConfiguration自动配置失效

原文:https://www.cnblogs.com/mrlliuchao/p/10305409.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!