| package com.ruoyi.device.hiksdk.config; | 
|   | 
| import io.minio.MinioClient; | 
| import lombok.Data; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.springframework.beans.factory.annotation.Value; | 
| import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; | 
| import org.springframework.core.io.ClassPathResource; | 
| import org.springframework.core.io.Resource; | 
| import org.springframework.stereotype.Component; | 
|   | 
| import java.io.IOException; | 
| import java.util.Properties; | 
|   | 
| /** | 
|  * @Description: | 
|  * @ClassName: MinioClientSingleton | 
|  * @Author: 刘苏义 | 
|  * @Date: 2023年05月18日9:32 | 
|  * @Version: 1.0 | 
|  **/ | 
|   | 
| @Slf4j(topic = "minio") | 
| @Component | 
| public class MinioClientSingleton { | 
|   | 
|     public static String domainUrl; | 
|     private static String accessKey; | 
|     private static String secretKey; | 
|   | 
|     private volatile static MinioClient minioClient; | 
|   | 
|     static { | 
|         domainUrl = getYmlNew("minio.endpoint"); | 
|         accessKey = getYmlNew("minio.accessKey"); | 
|         secretKey = getYmlNew("minio.secretKey"); | 
|         log.debug("minio信息:" + domainUrl + "(" + accessKey + "/" + secretKey + ")"); | 
|     } | 
|   | 
|     /** | 
|      * 获取minio客户端实例 | 
|      * | 
|      * @return {@link MinioClient} | 
|      */ | 
|     public static MinioClient getMinioClient() { | 
|         if (minioClient == null) { | 
|             synchronized (MinioClientSingleton.class) { | 
|                 if (minioClient == null) { | 
|                     minioClient = MinioClient.builder() | 
|                             .endpoint(domainUrl) | 
|                             .credentials(accessKey, secretKey) | 
|                             .build(); | 
|                 } | 
|             } | 
|         } | 
|         return minioClient; | 
|     } | 
|   | 
|     /*yml配置信息获取*/ | 
|     public static String getYmlNew(String key) { | 
|         Resource resource = new ClassPathResource("application-ard.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(); | 
|     } | 
|   | 
| } |