MinioConfig.java 1.23 KB
package com.pashanhoo.common.minio;

import io.minio.MinioClient;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @author CAIYONGSONG
 * @commpany www.pashanhoo.com
 * @date 2022/7/20
 */
@Data
@Component
@ConfigurationProperties(prefix = "minio")
public class MinioConfig {
    private Logger log = LoggerFactory.getLogger(MinioConfig.class);

    // minio地址
    private String minioUrl;
    //minio账号
    private String accessKey;
    //minio密码
    private String secretKey;
    //存储桶名称 */
    public String bucketName;
    // "如果是true,则用的是https而不是http,默认值是true"
    public static Boolean secure = false;


    @Bean
    public MinioClient getMinioClient(){
        log.info("初始化MinioClient客户端:minioUrl:" + minioUrl + ",accessKey:" + accessKey + ",secretKey:" + secretKey);
        MinioClient minioClient = MinioClient.builder()
                .endpoint(minioUrl)
                .credentials(accessKey,secretKey)
                .build();
        return minioClient;
    }

}