今天在url中直接访问静态资源时报如下404错误:
This application has no explicit mapping for /error, so you are seeing this as a fallback.
报错原因:
当spring boot版本升级为2.x时,访问静态资源就会被HandlerInterceptor拦截;
解决办法:
重写WebMvcConfigurer中的addInterceptors方法即可,代码如下:
@Configuration
public class myconfig implements WebMvcConfigurer {
private final Logger logger = LoggerFactory.getLogger(myconfig.class);
@Override
public void addInterceptors(InterceptorRegistry registry) {
logger.info("add interceptors");
registry.addInterceptor(new MyInterceptor()).excludePathPatterns("/index.html","/","/user/login","/static/**","/resources/**","/public/**");
}
}
其中,MyInterceptor()类的代码如下:
public class MyInterceptor implements HandlerIntercep