springboot 自定义配置文件

来源:互联网 发布:linux sosreport 编辑:程序博客网 时间:2024/06/04 23:36

除了application.yml ,自定义另外的配置文件,如何读取。

bus.yml:

email: xxxx@163.comscheduleEnable: true

定义配置文件读取类:

/**   bus.yml 参数读取 * @author xz * */@Component@PropertySource("classpath:bus.yml")@ConfigurationPropertiespublic class BusinessConfig {    private String email;    private boolean scheduleEnable;    public boolean isScheduleEnable() {        return scheduleEnable;    }    public void setScheduleEnable(boolean scheduleEnable) {        this.scheduleEnable = scheduleEnable;    }    public String getEmail() {        return email;    }    public void setEmail(String email) {        this.email = email;    }}

使用:

    @Autowired    BusinessConfig busConfig;    // 正常使用
阅读全文
0 0
原创粉丝点击