最简洁方式:使用API
在配置文件下写配置类SpringMvcSupport,并且让SpringMVC扫描到此文件夹@ComponentScan({"com.itheima.controller","com.itheima.config"})
SpringMvcSupport配置类如下
@Configuration
public class SpringMvcSupport extends WebMvcConfigurationSupport {
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/pages/**").addResourceLocations("/pages/");
registry.addResourceHandler("/css/**").addResourceLocations("/css/");
registry.addResourceHandler("/js/**").addResourceLocations("/js/");
registry.addResourceHandler("/plugins/**").addResourceLocations("/plugins/");
}
}
步骤:
1、在config文件下写SpringMvcConfig配置类
2、在SpringMvcConfig也就是SpringMVC核心配置类中扫描到此文件夹,那么此配置类就会被扫描到
SpringMvcConfig类如下:文章来源:https://www.toymoban.com/news/detail-692452.html
@Configuration
@ComponentScan({"com.itheima.controller","com.itheima.config"})
@EnableWebMvc
public class SpringMvcConfig {
}
如果不行,重启啥的。代码肯定是没错的。文章来源地址https://www.toymoban.com/news/detail-692452.html
到了这里,关于Tomcat加载静态资源--防止SpringMVC拦截的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!