码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2019-01-22 19:10:24      阅读:881      评论:0      收藏:0      [点我收藏+]

标签:remes   失效   resources   over   手动   col   tor   ini   cat   

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自动配置失效

标签:remes   失效   resources   over   手动   col   tor   ini   cat   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!