springboot打成jar后无法读取根路径和文件

ClassLoader.getSystemResourceAsStream(authenticationFileName)
PropertiesUtils.class.getClass().getResourceAsStream("/authentication.properties")

未打包时都可以获取到根路径和文件,打包后报java.lang.NullPointerException

ClassPathResource resource = new ClassPathResource("application.yml");
InputStream inputStream = resource.getInputStream();

这是因为打包后Spring试图访问文件系统路径,但无法访问JAR中的路径。 
因此必须使用resource.getInputStream()

猜你喜欢

转载自blog.csdn.net/weixin_39986856/article/details/81271460
今日推荐