自定义yml文件,获取配置参数
操作yml文件依赖
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.29</version>
</dependency>
mqtt链接参数,及读取yml文件工具
public class MqttParamObj {
public String mqttBrokerIp;
public Short mqttBrokerPort;
public String userName;
public String password;
public String mqttClientId;
public static MqttParamObj readConfigFile(){
MqttParamObj mqttParamObj = null;
File file = new File(System.getProperty("user.dir") + "/MqttParams.yml");
try {
InputStream fileInputStream = new FileInputStream(file);
if(Objects.nonNull(fileInputStream)){
Yaml yaml = new Yaml();
mqttParamObj = yaml.loadAs(fileInputStream, MqttParamObj.class);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return mqttParamObj;
}
}
MqttParams.yml 文件位置
