41 lines
1.1 KiB
Java
41 lines
1.1 KiB
Java
package com.guwan.config;
|
|
|
|
import io.minio.MinioClient;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
/**
|
|
* 对象存储工具类
|
|
*/
|
|
@Component
|
|
public class MinioConfig {
|
|
@Autowired
|
|
private GlobalValue globalValue;
|
|
|
|
public String getMinioEndpoint() {
|
|
return globalValue.getMinioEndpoint();
|
|
}
|
|
|
|
|
|
public String getBucketName(){
|
|
return globalValue.getMinioBucketName();
|
|
}
|
|
@Bean("minioClient")
|
|
public MinioClient minioClient(){
|
|
MinioClient minioClient=null;
|
|
try {
|
|
minioClient = new MinioClient(globalValue.getMinioEndpoint(),
|
|
// globalValue.getMinioPort(),
|
|
globalValue.getMinioAccessKey(),
|
|
globalValue.getMinioSecretKey());
|
|
if (!minioClient.bucketExists(globalValue.getMinioBucketName())) {
|
|
minioClient.makeBucket(globalValue.getMinioBucketName());
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return minioClient;
|
|
}
|
|
}
|