关于SpringBoot 部署到Linux服务器 找不到static下的静态资源问题
////因为Springboot是内嵌web容器,其特点是只有一个jar文件,在容器启动后不会解压缩,//这里就有一个问题,由于文件被保存在jar中,会导致读取失败,this.getClass().getResource("/")+fileName在本地windows下能完美找到路径,//比如;File logoFile = new File(ClassUtils.g...
·
//
// 因为Springboot是内嵌web容器,其特点是只有一个jar文件,在容器启动后不会解压缩,
// 这里就有一个问题,由于文件被保存在jar中,会导致读取失败,this.getClass().getResource("/")+fileName在本地windows下能完美找到路径,
// 比如;File logoFile = new File(ClassUtils.getDefaultClassLoader().getResource("").getPath() + "static/images/codelogo.jpg"),
// 可是在linux测试服务器下就失败,所以读取jar中的文件只能用流读取,不能用file。
public static InputStream getInputStream(String path) throws IOException {
ClassPathResource classPathResource = new ClassPathResource(path);
return classPathResource.getInputStream();
}
更多推荐
已为社区贡献1条内容
所有评论(0)