Spring Boot 中默认提供了五个静态资源存储路径:
- classpath:/META-INF/resources/
- classpath:/resources/
- classpath:/static/
- classpath:/public/
- /(webapp)
五个位置,优先级依次降低。
如果需要自定义静态资源位置,有两种方式:
-
application.properties 中进行配置
spring.mvc.static-path-pattern=/static public MyErrorViewResolver(ApplicationContext applicationContext, WebProperties webProperties) { super(applicationContext, webProperties.getResources()); } @Override public ModelAndView resolveErrorView(HttpServletRequest request, HttpStatus status, Mapmodel) { ModelAndView mv = new ModelAndView(); mv.setViewName("aaa/error"); Map map = new HashMap<>(); Set keySet = model.keySet(); for (String key : keySet) { map.put(key, model.get(key)); } map.put("message", "出错啦"); mv.addAllObjects(map); return mv; } }



