直接上例子,记录下:
我的文件路径: 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);
本文探讨了在本地开发与发布到ECS环境时,如何处理classpath资源路径问题,重点在于图片资源的加载和ClassPathResource类的使用技巧。
21万+

被折叠的 条评论
为什么被折叠?



