直接上例子,记录下:
我的文件路径: Resource/temp/logo.png
本地启动项目,随便咋折腾,编译后只要target下的classes下对应的路径有文件,那么就没问题。
但是在发布到ecs以后,会报错:
class path resource [XX] cannot be resolved to absolute file path
because it does not reside…
因为我的是图片,所以:
ClassPathResource classPathResource = new ClassPathResource("/temp/logo.png");
byte[] logoData = FileCopyUtils.copyToByteArray(classPathResource.getInputStream());
ByteArrayInputStream in = new ByteArrayInputStream(logoData);
BufferedImage logo = ImageIO.read(in);