Compare commits
2 Commits
d179eda734
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1f2683426 | ||
|
|
098f8ff175 |
@@ -6,10 +6,10 @@ import lombok.Data;
|
|||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OSS配置类,存储连接所需的核心参数
|
* OSS配置类,存储连接所需的核心参数
|
||||||
|
*
|
||||||
* @author web2023
|
* @author web2023
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@@ -19,18 +19,14 @@ import org.springframework.util.StringUtils;
|
|||||||
@Data
|
@Data
|
||||||
public class AliYunOssConfig {
|
public class AliYunOssConfig {
|
||||||
|
|
||||||
private String endpoint;
|
private String endpoint = "xx";
|
||||||
private String accessKey;
|
private String accessKey = "xx";
|
||||||
private String secretKey;
|
private String secretKey = "xx";
|
||||||
private String bucket;
|
private String bucket = "xx";
|
||||||
|
|
||||||
@Bean(destroyMethod = "shutdown")
|
@Bean(destroyMethod = "shutdown")
|
||||||
public OSS getAliYunClient() {
|
public OSS getAliYunClient() {
|
||||||
// 1. 校验配置(避免因配置为空导致Bean创建失败)
|
return new OSSClientBuilder().build(
|
||||||
if (!StringUtils.hasText(endpoint) || !StringUtils.hasText(accessKey) || !StringUtils.hasText(secretKey)) {
|
|
||||||
throw new IllegalArgumentException("OSS配置缺失:endpoint/accessKey/secretKey不能为空");
|
|
||||||
}
|
|
||||||
return new OSSClientBuilder().build(
|
|
||||||
this.getEndpoint(),
|
this.getEndpoint(),
|
||||||
this.getAccessKey(),
|
this.getAccessKey(),
|
||||||
this.getSecretKey()
|
this.getSecretKey()
|
||||||
@@ -38,5 +34,4 @@ public class AliYunOssConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user