读取yaml 的配置文件
配置文件信息
iot_saas_tenement:
user_id: 7........8d9b
private_key: MII.......qQ==
bj_url: http://4.....5:8088
project_name: iot_s.......roject
device_name: te.....ice

创建一个类 ProxyProperties 读取配置文件信息,并对外提供get方法
package com.purvardata.himp.third.bj.utils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
public final class ProxyProperties {
@Value("${iot_saas_tenement.bj_url}")
private static String url;
@Value("${iot_saas_tenement.user_id}")
private static String userId;
@Value("${iot_saas_tenement.private_key}")
private String private_key;
private static String privateKey;
@Value("${iot_saas_tenement.project_name}")
private String project_name;
private static String projectName;
@Value("${iot_saas_tenement.device_name}")
private String device_name;
private static String deviceName;
privateKey=this.private_key;
projectName=this.project_name;
deviceName=this.device_name;
public static String getUrl() {
public static String getUserId() {
public static String getPrivateKey() {
public static String getProjectName() {
public static String getDeviceName() {
目标静态方法通过get方法获取对应的属性

通过类 ResourceBundle 读取 config.properties 的配置文件
config.properties配置文件信息
userId=7dd.......9b
private_key=MIIC........Q==
url=http://4......5:8088
project_name=iot_sa..............ect

定义读取 配置类 PropertiesUtils,注意 config.properties 目录,要是和 ResourceBundle.getBundle("config")路径一致,我这里放根路径了
import java.util.ResourceBundle;
public class PropertiesUtils {
private static ResourceBundle bundle = ResourceBundle.getBundle("config");
public static String getValue(String key) {
return bundle.getString(key);
使用配置类 PropertiesUtils.getValue 获取配置文件 config.properties 的信息
