this.getClass().getClassLoader() 获取文件为null

    在resources/META-INF下创建文件夹,然后将文件置于文件夹内。   第一次获取成功,其余为null。暂不明原 因。

String sourcePath = this.getClass().getClassLoader().getResource("file.txt").getPath();

后将文件置于/META-INF下同层下,此情况没再发生。运行环境为springBoot,多模块开发。

猜你喜欢

转载自pljj000.iteye.com/blog/2400969