Spring Boot的资源加载路径和classpath问题

1、Spring Boot默认加载文件的路径

  • /META-INF/resources/
  • /resources/
  • /static/
  • /public/

也可以从Spring Boot的源码看到:

private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { 
    "classpath:/META-INF/resources/",
    "classpath:/resources/", 
    "classpath:/static/", 
    "classpath:/public/"
 };

2、Classpath含义

  1. 存放各种资源配置文件 application.yml
  2. 存放模板文件
  3. 存放class文件对应的是项目开发时的src目录编译文件

3、总结

classpath就是springboot定位资源的入口

 

posted @ 2021-08-11 15:35  wang_longan  阅读(399)  评论(0编辑  收藏  举报