spring-boot可拓展的ProPertiesConfig

58 阅读1分钟

1.编写yml文件

dbc:
  ds:
    url: jdbc:mysql://localhsot:3306/xxx?characterEncoding=utf-8&serverTimezone=Asia/Shanghai
    username: root
    password: root

2.创建Properties类

@Configuration
@Component
@Data
@ConfigurationProperties(prefix = "dbc")
public class PropertiesConfig {

    private Ds ds = new Ds();


    @Data
    public static class Ds{
        private String url;
        private String username;
        private String password;

    }

}

3.使用

@Resource
private PropertiesConfig PropertiesConfig;