[英]Get images from resources folder on a JAR in a Spring boot application
I have a spring boot application.我有一个 spring 启动应用程序。 When I deploy mi application in a local Tomcat as a war, I'm able to use images from the resources folder by this way:
当我在本地 Tomcat 部署 mi 应用程序作为战争时,我可以通过这种方式使用资源文件夹中的图像:
ResourceUtils.getFile("classpath:Logo.png")
My problem is when I package the applications as a JAR. Seems that is not able to find the images... After some time searching the inte.net, I tried a few different things, but none have worked so far.我的问题是当我将应用程序 package 作为 JAR 时。似乎无法找到图像...在搜索 inte.net 一段时间后,我尝试了一些不同的方法,但到目前为止都没有用。
Resource resource = new ClassPathResource("classpath:Logo.png");
InputStream inputStream = resource.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
imagePart.attachFile(FileCopyUtils.copyToString(reader));
Edit: Project Structure编辑:项目结构
Could you please share the project structure?你能分享一下项目结构吗? If the images are placed in test/resources/ or main/resources folder then the jar will not have any resources from tests or main folder.
如果图像放置在test/resources/或main/resources文件夹中,则 jar 将没有来自 tests 或 main 文件夹的任何资源。 That could be one possibility.
这可能是一种可能性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.