spring-boot自定义yml读取

通过注解方式加载自定义yml文件

@Component
@PropertySource(value = "conf/jgpt.yml")//指定文件位置
@ConfigurationProperties(prefix = "jgpt-api")// 指定前缀
@Data
public class JgptConst {
    public static String clientId;
    //加载对应数据
    @PostConstruct
    public static void setClientId(String clientId) {
        JgptConst.clientId = clientId;
    }
}

yml文件

jgpt-api:
  clientId: 10105
    

原文地址:https://www.cnblogs.com/geekswg/p/15225648.html