Error Caused by: java.io.FileNotFoundException for file under src/main/resources/config/env/dev2 in SpringBoot 2.0 application

Error Caused by: java.io.FileNotFoundException for file under src/main/resources/config/env/dev2 in SpringBoot 2.0 application

BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(propertyFile))));

在这里,我尝试将 propertyFile 指定为 "/envsettings/xdev2/env.properties""envsettings/xdev2/env.properties",但仍然遇到相同文件未找到的问题。

当我看到目录结构时,我看到 C:\Users\primary\git\dev\SpringBoot\Originations\target\odyssey\WEB-INF\classes\config75\envsettings\dev2\env.properties

有人可以帮忙吗?

永远不要像那样访问类路径中的资源。使用 Class.getResourceAsStream or ClassLoader.getResourceAsStream:

BufferedReader br = new BufferedReader(
    this.getClass().getResourceAsStream("path/relative/to/classpath/resource.file")
);