我是靠谱客的博主 过时短靴,这篇文章主要介绍spring boot项目打成jar包,读取不到fsatClient.conf文件,现在分享给大家,希望可以做个参考。

问题:

使用fastdfs客户端上传文件,采用ClientGlobal.init()初始化配置时读取不到文件内容

错误代码:

String filePath = cpr.getClassLoader().getResource(“fdfs_client.conf”).toURI().getPath();
ClientGlobal.init(filePath);

错误原因:

jar包中读取不到classpath路径文件

解决办法:

在这里插入图片描述
clientGlobal中还有另外一种初始化客户端的方法,initByProperties。
因此,修改代码为以下即可解决问题:
Properties properties = new Properties();
// 使用ClassLoader加载properties配置文件生成对应的输入流
InputStream in = new ClassPathResource(“fdfs_client.properties”).getInputStream();
// 使用properties对象加载输入流
properties.load(in);
ClientGlobal.initByProperties(properties);

最后

以上就是过时短靴最近收集整理的关于spring boot项目打成jar包,读取不到fsatClient.conf文件的全部内容,更多相关spring内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(165)

评论列表共有 0 条评论

立即
投稿
返回
顶部