标签: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