文件路径在 .jar (Spring) 中不起作用

时间:2021-07-31 22:48:01

标签: spring spring-boot

本地一切正常,但是当我启动 jar 时,
我收到一个错误,提示它无法识别路径。
代码如下所示:

Path path = Paths.get(getClass().getClassLoader().getResource("classpath:images/" + image_title.getOriginalFilename()).toURI());
              
Files.copy(image_title.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING);

错误:

2021-08-01 00:41:47.174 ERROR 13188 --- [nio-8080-exec-7] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause

java.lang.NullPointerException: null

0 个答案:

没有答案
相关问题