春季启动-无法从资源jar加载文件...在_some_线程上

问题描述

我有一个spring-boot应用程序。如果请求从RestController终结点方法读取文件,则可以加载资源(在app jar中)中的文件,而不会出现任何问题。

但是,还有一条执行路径正在使用连接到RestController的另一个线程 not 。从那个线程,我得到一个例外:

java.io.FileNotFoundException: class path resource [path-in-jar] cannot be resolved to URL because it does not exist

我正在像这样从罐子中读取文件

public String getContent(String resourcePath) {
    ClassPathResource cl = new ClassPathResource(resourcePath);
    URL url = cl.getURL(); // <-- exception is raised over here
    String content;
    try (InputStream in = url.openStream()) {
      content = new String(in.readAllBytes(),StandardCharsets.UTF_8);
    }
    return content;
}

您知道我该如何解决吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)