需求:
springboot项目最后要打成jar运行,但是如果配置文件在jar包中,则之后都无法再修改配置文件了,不合理。因此配置文件应该放在jar包外面
实现:
配置文件在config文件夹中,config文件夹和jar在同一级目录下,如下图所示
在编码阶段,config文件夹和src同一级目录下,如下图所示
1.读取配置文件的属性
Properties properties = new Properties();
String filePath = System.getProperty("user.dir") + "/config/server.properties";
InputStream in = new BufferedInputStream(new FileInputStream(filePath));
properties.load(in);
String ip = properties.getProperty("ip");
参考文章:https://blog.youkuaiyun.com/zhuchunyan_aijia/article/details/78673809