lifuquan 1 jaar geleden
bovenliggende
commit
4b439418ff

+ 6 - 6
doc/MinioServiceImpl.java

@@ -62,9 +62,9 @@ public class MinioServiceImpl implements FileService {
                     .object(object)
                     .method(Method.GET)
                     .build()), minioConfig.getEndpoint());
-        } catch (ErrorResponseException | InsufficientDataException | InternalException | InvalidKeyException |
-                 InvalidResponseException | IOException | NoSuchAlgorithmException | XmlParserException |
-                 ServerException e) {
+        } catch (ErrorResponseException | InsufficientDataException | InternalException | InvalidKeyException
+                | InvalidResponseException | IOException | NoSuchAlgorithmException | XmlParserException
+                | ServerException e) {
             throw new MyRuntimeException(e);
         }
     }
@@ -94,9 +94,9 @@ public class MinioServiceImpl implements FileService {
             map.put("headers", response.headers());
             map.put("region", response.region());
             return map;
-        } catch (ErrorResponseException | InsufficientDataException | InternalException | InvalidKeyException |
-                 InvalidResponseException | IOException | NoSuchAlgorithmException | ServerException |
-                 XmlParserException e) {
+        } catch (ErrorResponseException | InsufficientDataException | InternalException | InvalidKeyException
+                | InvalidResponseException | IOException | NoSuchAlgorithmException | ServerException
+                | XmlParserException e) {
             throw new MyRuntimeException(e);
         }
     }

+ 1 - 1
pom.xml

@@ -40,7 +40,7 @@
         <dependency>
             <groupId>io.minio</groupId>
             <artifactId>minio</artifactId>
-            <version>8.5.2</version>
+            <version>8.5.4</version>
         </dependency>
         <!-- spring-boot-starter-web -->
         <dependency>

+ 20 - 2
src/main/java/com/nokia/minio_client/config/MinioClientAutoConfiguration.java

@@ -1,14 +1,32 @@
 package com.nokia.minio_client.config;
 
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
 import com.nokia.minio_client.properties.MinioClientProperties;
+import com.nokia.minio_client.service.MinioClientService;
+
+import io.minio.MinioClient;
 
 @Configuration
-@ComponentScan("com.nokia.minio_client")
 @EnableConfigurationProperties(MinioClientProperties.class)
 public class MinioClientAutoConfiguration {
 
+    @Autowired
+    private MinioClientProperties properties;
+
+    @Bean
+    public MinioClient minioClient() {
+        return MinioClient.builder()
+                .endpoint(properties.getEndpoint())
+                .credentials(properties.getAccess(), properties.getSecret())
+                .build();
+    }
+
+    @Bean
+    public MinioClientService minioClientService() {
+        return new MinioClientService();
+    }
 }

+ 6 - 1
src/main/java/com/nokia/minio_client/service/MinioClientService.java

@@ -1,14 +1,19 @@
 package com.nokia.minio_client.service;
 
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import io.minio.MinioClient;
 import lombok.extern.slf4j.Slf4j;
 
 @Slf4j
 @Service
 public class MinioClientService {
 
+    @Autowired
+    private MinioClient minioClient;
+
     public void test() {
-        log.info("====================");
+        log.info("===================={}", minioClient.toString());
     }
 }