注入多个相关的配置对象

一 配置文件

fs:
  # 云存储配置
  files-server:
    type: oss4546
    qiniu:
      accessKey: 2312243refefet
      secretKey: 2132435464rtre
      bucket: xxxxxxxxxx655xxxxxxxxx
      path: xxxxxxxxxxx54xxxxxxxx
    #oss配置
    oss:
      accessKey: xxxx32564xxxxxxxxxxxxxxx
      secretKey: xxxxxxserxxxxxxxxxxxxx
      endpoint: xxxxxxxxxxxxxx564xxxxx
      bucket: xxxxxxxxxxxxxxxx312xxx
      path: xxxxxxxxxxxxxxxx345621xxx  

二 java配置类

2.1 fs上传配置资源类
@Setter
@Getter
@Configuration
@ConfigurationProperties(prefix = "fs.files-server")
public class FsServerProperties {

    /**
     * 自动化配置
     * type:oss or qiniu
     */
    private String type = "qiniu";



    /**
     * 七牛配置
     */
    QiniuProperties qiniu = new QiniuProperties();

    /**
     * oss配置
     */
    OssProperties oss = new OssProperties();
}
2.2 oss配置资源类
@Getter
@Setter
public class OssProperties {

    private String accessKey;

    private String secretKey;

    private String endpoint;

    private String bucket;

    private String path;
}
2.3 七牛云配置资源类
@Getter
@Setter
public class QiniuProperties {

    private String accessKey;

    private String secretKey;

    private String bucket;

    private String path;
}

三 使用

 @Autowired
 private  FsServerProperties fsProp;
posted @ 2023-05-24 11:29  进击的小蔡鸟  阅读(55)  评论(0编辑  收藏  举报