From d3f18a73cd5a903fccf99cd162ab72adec738aff Mon Sep 17 00:00:00 2001
From: SZH <szh_hello@163.com>
Date: 星期二, 19 七月 2022 16:07:40 +0800
Subject: [PATCH] 变更minio配置
---
safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/minioDemo/service/MinioAccessService.java | 128 +++++++++++++++++++++++++
safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/database/DruidConfig.java | 6
safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/minioDemo/controller/MinioTest.java | 31 ++++++
safePlatfrom-out-web/src/main/resources/config/application-dev.yaml | 10 +
safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/minioDemo/config/MinioConfig.java | 90 ++++++++++++++++++
safePlatfrom-out-web/src/main/resources/config/application-out-dev.yaml | 12 +-
6 files changed, 265 insertions(+), 12 deletions(-)
diff --git a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/database/DruidConfig.java b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/database/DruidConfig.java
index 065a578..d7922fd 100644
--- a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/database/DruidConfig.java
+++ b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/database/DruidConfig.java
@@ -44,7 +44,7 @@
// ds.setXaDataSourceClassName("com.alibaba.druid.pool.xa.DruidXADataSource");
ds.setXaDataSourceClassName(datasourceClass);
ds.setUniqueResourceName("goalmanage");
- ds.setPoolSize(5);
+ ds.setPoolSize(2);
ds.setXaProperties(prop);
return ds;
@@ -60,7 +60,7 @@
// ds.setXaDataSourceClassName("com.alibaba.druid.pool.xa.DruidXADataSource");
ds.setXaDataSourceClassName(datasourceClass);
ds.setUniqueResourceName("emergency");
- ds.setPoolSize(5);
+ ds.setPoolSize(2);
ds.setXaProperties(prop);
return ds;
}
@@ -74,7 +74,7 @@
ds.setXaDataSourceClassName(datasourceClass);
// ds.setXaDataSourceClassName("com.alibaba.druid.pool.xa.DruidXADataSource");
ds.setUniqueResourceName("incidentmanage");
- ds.setPoolSize(5);
+ ds.setPoolSize(2);
ds.setXaProperties(prop);
return ds;
}
diff --git a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/minioDemo/config/MinioConfig.java b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/minioDemo/config/MinioConfig.java
new file mode 100644
index 0000000..ebfc4cb
--- /dev/null
+++ b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/minioDemo/config/MinioConfig.java
@@ -0,0 +1,90 @@
+package com.gkhy.safePlatform.minioDemo.config;
+
+import io.minio.MinioClient;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.stereotype.Component;
+
+@Component
+@ConfigurationProperties(prefix = "minio")
+public class MinioConfig {
+
+ private String endpoint;
+
+ private int port;
+
+ private String accessKey;
+
+ private String secretKey;
+
+ private Boolean secure;
+
+ private String bucketName;
+
+ private String urlPrefix;
+
+ @Bean
+ public MinioClient getMinioClient(){
+ String endpointUrl = "http://"+endpoint+":"+port;
+ MinioClient minioClient = MinioClient.builder().endpoint(endpointUrl)
+ .credentials(accessKey,secretKey)
+ .build();
+ return minioClient;
+ }
+
+ public String getEndpoint() {
+ return endpoint;
+ }
+
+ public void setEndpoint(String endpoint) {
+ this.endpoint = endpoint;
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ public String getAccessKey() {
+ return accessKey;
+ }
+
+ public void setAccessKey(String accessKey) {
+ this.accessKey = accessKey;
+ }
+
+ public String getSecretKey() {
+ return secretKey;
+ }
+
+ public void setSecretKey(String secretKey) {
+ this.secretKey = secretKey;
+ }
+
+ public Boolean getSecure() {
+ return secure;
+ }
+
+ public void setSecure(Boolean secure) {
+ this.secure = secure;
+ }
+
+ public String getBucketName() {
+ return bucketName;
+ }
+
+ public void setBucketName(String bucketName) {
+ this.bucketName = bucketName;
+ }
+
+ public String getUrlPrefix() {
+ return urlPrefix;
+ }
+
+ public void setUrlPrefix(String urlPrefix) {
+ this.urlPrefix = urlPrefix;
+ }
+}
diff --git a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/minioDemo/controller/MinioTest.java b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/minioDemo/controller/MinioTest.java
new file mode 100644
index 0000000..a9edc3e
--- /dev/null
+++ b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/minioDemo/controller/MinioTest.java
@@ -0,0 +1,31 @@
+package com.gkhy.safePlatform.minioDemo.controller;
+
+import com.gkhy.safePlatform.minioDemo.service.MinioAccessService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+
+@RestController
+@RequestMapping(value = "/test/file")
+public class MinioTest {
+
+ @Autowired
+ private MinioAccessService minioAccessService;
+
+ @RequestMapping(value = "/up",method = RequestMethod.GET)
+ private Object testFileUpload(){
+ return minioAccessService.uploadFile();
+ }
+
+ @RequestMapping(value = "/assume",method = RequestMethod.GET)
+ public Object testMinioSts(String obj){
+ return minioAccessService.getObjectUrl(obj);
+ }
+
+ @RequestMapping(value = "/put/presign",method = RequestMethod.GET)
+ public Object getPutObjectUrl(String obj){
+ return minioAccessService.getPutUrl(obj);
+ }
+}
diff --git a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/minioDemo/service/MinioAccessService.java b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/minioDemo/service/MinioAccessService.java
new file mode 100644
index 0000000..84b0682
--- /dev/null
+++ b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/minioDemo/service/MinioAccessService.java
@@ -0,0 +1,128 @@
+package com.gkhy.safePlatform.minioDemo.service;
+
+import com.gkhy.safePlatform.minioDemo.config.MinioConfig;
+import io.minio.BucketExistsArgs;
+import io.minio.GetPresignedObjectUrlArgs;
+import io.minio.MinioClient;
+import io.minio.UploadObjectArgs;
+import io.minio.errors.*;
+import io.minio.http.Method;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.util.HashMap;
+import java.util.Map;
+
+@Service
+public class MinioAccessService {
+
+ @Resource
+ private MinioConfig minioConfig;
+
+ @Autowired
+ private MinioClient minioClient;
+
+ public Object uploadFile(){
+ try {
+ boolean bucketCheck =
+ minioClient.bucketExists(BucketExistsArgs.builder()
+ .bucket(minioConfig.getBucketName()).build());
+ if(bucketCheck == true){
+ minioClient.uploadObject(UploadObjectArgs.builder().bucket(minioConfig.getBucketName())
+ .object("1.b3dm")
+ .filename("G:\\b3dm\\b3dm60\\Tile_+000_+004\\Tile_+000_+004.b3dm")
+ .build());
+ System.out.println("上传成功");
+ }
+ } catch (ServerException e) {
+ e.printStackTrace();
+ } catch (InsufficientDataException e) {
+ e.printStackTrace();
+ } catch (ErrorResponseException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ } catch (InvalidKeyException e) {
+ e.printStackTrace();
+ } catch (InvalidResponseException e) {
+ e.printStackTrace();
+ } catch (XmlParserException e) {
+ e.printStackTrace();
+ } catch (InternalException e) {
+ e.printStackTrace();
+ }
+ return "1";
+ }
+
+ public String getObjectUrl(String objectName){
+ String url = null;
+ try {
+ url = minioClient.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder()
+ .method(Method.GET)
+ .bucket(minioConfig.getBucketName())
+ .object(objectName)
+ .expiry(60).build());
+ } catch (ErrorResponseException e) {
+ e.printStackTrace();
+ } catch (InsufficientDataException e) {
+ e.printStackTrace();
+ } catch (InternalException e) {
+ e.printStackTrace();
+ } catch (InvalidKeyException e) {
+ e.printStackTrace();
+ } catch (InvalidResponseException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ } catch (XmlParserException e) {
+ e.printStackTrace();
+ } catch (ServerException e) {
+ e.printStackTrace();
+ }
+ return url;
+ }
+
+ public String getPutUrl(String objName){
+ String url = null;
+ try {
+ Map<String, String> reqParams = new HashMap<>();
+ reqParams.put("response-content-type", "application/json");
+ url = minioClient.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder()
+ .method(Method.PUT)
+ .bucket(minioConfig.getBucketName())
+ .object(objName)
+ .expiry(60*2)
+ .extraQueryParams(reqParams)
+ .build());
+ } catch (ErrorResponseException e) {
+ e.printStackTrace();
+ } catch (InsufficientDataException e) {
+ e.printStackTrace();
+ } catch (InternalException e) {
+ e.printStackTrace();
+ } catch (InvalidKeyException e) {
+ e.printStackTrace();
+ } catch (InvalidResponseException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ } catch (XmlParserException e) {
+ e.printStackTrace();
+ } catch (ServerException e) {
+ e.printStackTrace();
+ }
+ return url;
+ }
+
+
+}
diff --git a/safePlatfrom-out-web/src/main/resources/config/application-dev.yaml b/safePlatfrom-out-web/src/main/resources/config/application-dev.yaml
index fdbf22d..6300b48 100644
--- a/safePlatfrom-out-web/src/main/resources/config/application-dev.yaml
+++ b/safePlatfrom-out-web/src/main/resources/config/application-dev.yaml
@@ -99,12 +99,14 @@
minio:
endPoint: 192.168.0.52
- port: 9001
- accessKey: kH6eiQtNrWqGNb1r
- secretKey: ff5ykVUJJn0hi5PghsitdGNSsrW0Xrju
+ port: 9000
+ accessKey: oddER8eSv211WVG3
+ secretKey: TeaEh8eWNhBbjCYK3G6cIX2QGYECwo7M
secure: false
- bucketName: szh-stu
+ bucketName: safeplatform-dev
urlPrefix: http://192.168.0.52/file
+ #用户名 gkhy_team_out_dev
+ #密码 12345678
token:
diff --git a/safePlatfrom-out-web/src/main/resources/config/application-out-dev.yaml b/safePlatfrom-out-web/src/main/resources/config/application-out-dev.yaml
index 017d327..0f16b24 100644
--- a/safePlatfrom-out-web/src/main/resources/config/application-out-dev.yaml
+++ b/safePlatfrom-out-web/src/main/resources/config/application-out-dev.yaml
@@ -32,7 +32,7 @@
type: com.alibaba.druid.pool.DruidDataSource
redis:
host: 192.168.0.52
- port: 6379
+ port: 6378
password: SEF98uvs98dUAUEF90Udssa
database: 0 # Redis 数据库号,默认为 0
timeout: 15000 # Redis 连接超时时间,单位:毫秒。
@@ -99,12 +99,14 @@
minio:
endPoint: 192.168.0.52
- port: 9001
- accessKey: kH6eiQtNrWqGNb1r
- secretKey: ff5ykVUJJn0hi5PghsitdGNSsrW0Xrju
+ port: 9000
+ accessKey: oddER8eSv211WVG3
+ secretKey: TeaEh8eWNhBbjCYK3G6cIX2QGYECwo7M
secure: false
- bucketName: szh-stu
+ bucketName: safeplatform-dev
urlPrefix: http://192.168.0.52/file
+ #用户名 gkhy_team_out_dev
+ #密码 12345678
token:
--
Gitblit v1.9.2