springboot 配置文件注入 yaml 注入值

一、yaml文件

minio:
  endpoint: http://<hostname>:<port>
  access-key: <access-key>
  secret-key: <secret-key>
  bucket-name: <bucket-name>

二、实体类(接收yaml注入值)

package com.wt.lease.common.minio;


import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Data
@Component
@ConfigurationProperties(prefix = "minio")
public class MinioProperties {
    private String endpoint;
    private String accessKey;
    private String secretKey;
    private String bucketName;
}

三、使用

@Autowired
private MinioProperties minioProperties;

 

posted @ 2025-05-11 23:03  市丸银  阅读(43)  评论(0)    收藏  举报