springboot访问项目中某个module的图片(服务器拿不到)

取项目中resource下的图片

ResourceUtils.getFile("classpath:static/manage/assert/images/qrcode/xy.png"));

本地执行是可以拿到文件,但是在服务器上就是拿不到

服务器显示的路径是有带!号的路径

拿图片路径============jar:file:/app/apps/cloud/cloud-web-m-assemble/target/cloud-web-m.jar!/BOOT-INF/lib/cloud-web-m-core-1.0.0-SNAPSHOT.jar!/static/manage/assert/images/qrcode/xy.png

最后修改工具类

使用如下的方法才使服务器拿到图片

java.net.URL url = this.getClass().getResource("/static/manage/assert/images/qrcode/xy.png"))

java.net.URL fileURL = this.getClass().getResource("/UI/image/background.jpg");
javax.swing.Image backGround = new ImageIcon(fileURL).getImage();
服务器一直直接拿File 的话,拿不到,后面通过拿URL就可以了,总之,蛋疼啊
 
原文地址:https://www.cnblogs.com/xuerong/p/8196201.html