Loading

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
posted @ 2021-09-04 01:17  独行侠X  阅读(512)  评论(1编辑  收藏  举报