‘liusuyi’
2023-08-23 cc4b3f8713b4c561c193fa1abdae0ab69b98750d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.ruoyi.storage.minio.utils;
 
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
 
/**
 * @Description:
 * @ClassName: MinioClientSingleton
 * @Author: 刘苏义
 * @Date: 2023年05月18日9:32
 * @Version: 1.0
 **/
@Slf4j(topic = "minio")
@Component
public class MinioConfig {
    @Value("${minio.endpoint}")
    private  String endpoint;
    @Value("${minio.accessKey}")
    private  String accessKey;
    @Value("${minio.secretKey}")
    private  String secretKey;
 
//    private volatile static MinioClient minioClient;
 
    @Bean
    public io.minio.MinioClient getMinioClient() {
        return io.minio.MinioClient.builder()
                .endpoint(endpoint)
                .credentials(accessKey, secretKey)
                .build();
    }
 
//    /**
//     * 获取minio客户端实例
//     *
//     * @return {@link MinioClient}
//     */
//    public static MinioClient getMinioClient() {
//        if (minioClient == null) {
//            synchronized (MinioClientSingleton.class) {
//                if (minioClient == null) {
//                    minioClient = MinioClient.builder()
//                            .endpoint(endpoint)
//                            .credentials(accessKey, secretKey)
//                            .build();
//                }
//            }
//        }
//        return minioClient;
//    }
    //    static {
//        domainUrl = getYmlNew("minio.endpoint");
//        accessKey = getYmlNew("minio.accessKey");
//        secretKey = getYmlNew("minio.secretKey");
//        log.debug("minio信息:" + domainUrl + "(" + accessKey + "/" + secretKey + ")");
//    }
    /*yml配置信息获取*/
//    public static String getYmlNew(String key) {
//        Resource resource = new ClassPathResource("application-prod.yml");
//        Properties properties = null;
//        try {
//            YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
//            yamlFactory.setResources(resource);
//            properties = yamlFactory.getObject();
//        } catch (Exception e) {
//            e.printStackTrace();
//            return null;
//        }
//        return properties.get(key).toString();
//    }
 
}