本文共 178 字,大约阅读时间需要 1 分钟。
在开发环境下我们可以用
ResourceUtils.getFile("classpath:pictures/a.png");
的方式读取资源,但是打成jar包后,访问就报错了,jar只能以流的方式读取,如下
ClassPathResource resource = new ClassPathResource(imagePath);
如上方式可以正确读取。
转载地址:http://chjqi.baihongyu.com/