在想加载 rsources
下的资源时,由于使用的是maven
,参考springboot项目中classpath指向了哪里,以及如何获取springboot项目默认的的classpath
1、用maven
构建(build
)项目时,默认的classpath
指向target/classes/
2、用maven
打包(package
)项目时,默认的classpath
指向jar
内部的WEB-INF/classes/
String filePath = "../../src/main/resources/static/MaintenanceTableTemplate.xlsx";
ClassPathResource classPathResource = new ClassPathResource(filePath);
在打包后并不会加载resources
下的资源,因此使用
String filePath = System.getProperty("user.dir")+"/src/main/resources/***.xlsx";
通过System.getProperty(“user.dir”)
获得的工作目录的绝对路径,在添加/src/main/resources
即可加载resources
下资源。