设置默认值

This commit is contained in:
wr
2026-01-13 16:37:27 +08:00
parent d179eda734
commit 098f8ff175

View File

@@ -10,6 +10,7 @@ import org.springframework.util.StringUtils;
/**
* OSS配置类存储连接所需的核心参数
*
* @author web2023
*/
@Configuration
@@ -19,18 +20,14 @@ import org.springframework.util.StringUtils;
@Data
public class AliYunOssConfig {
private String endpoint;
private String accessKey;
private String secretKey;
private String bucket;
private String endpoint = "xx";
private String accessKey = "xx";
private String secretKey = "xx";
private String bucket = "xx";
@Bean(destroyMethod = "shutdown")
public OSS getAliYunClient() {
// 1. 校验配置避免因配置为空导致Bean创建失败
if (!StringUtils.hasText(endpoint) || !StringUtils.hasText(accessKey) || !StringUtils.hasText(secretKey)) {
throw new IllegalArgumentException("OSS配置缺失endpoint/accessKey/secretKey不能为空");
}
return new OSSClientBuilder().build(
return new OSSClientBuilder().build(
this.getEndpoint(),
this.getAccessKey(),
this.getSecretKey()
@@ -38,5 +35,4 @@ public class AliYunOssConfig {
}
}