-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from lunasaw/3.1.9-SNAPSHOT
3.1.9 snapshot
- Loading branch information
Showing
46 changed files
with
218 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
ali-spring-boot-starter/src/main/java/com/luna/ali/oss/AliOssClientSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.luna.ali.oss; | ||
|
||
import com.aliyun.oss.ClientBuilderConfiguration; | ||
import com.aliyun.oss.OSS; | ||
import com.aliyun.oss.OSSClientBuilder; | ||
import com.luna.ali.config.AliConfigProperties; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.beans.factory.InitializingBean; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
|
||
/** | ||
* @author weidian | ||
* @description | ||
* @date 2023/4/16 | ||
*/ | ||
@Component | ||
public class AliOssClientSupport implements InitializingBean { | ||
|
||
@Autowired | ||
private AliConfigProperties aliConfigProperties; | ||
|
||
/** | ||
* 创建OSSClient实例 | ||
*/ | ||
private OSS client; | ||
|
||
public OSS getInstanceClient() { | ||
synchronized (AliOssClientSupport.class){ | ||
if (aliConfigProperties.getEnableCname() && StringUtils.isNotEmpty(aliConfigProperties.getDomain())) { | ||
ClientBuilderConfiguration conf = new ClientBuilderConfiguration(); | ||
// 设置是否支持CNAME。CNAME是指将自定义域名绑定到存储空间上。 | ||
conf.setSupportCname(true); | ||
return new OSSClientBuilder().build(aliConfigProperties.getDomain(), aliConfigProperties.getAccessKey(), | ||
aliConfigProperties.getSecretKey(), conf); | ||
} | ||
if (client == null) { | ||
this.client = new OSSClientBuilder().build(aliConfigProperties.getEndpoint(), aliConfigProperties.getAccessKey(), | ||
aliConfigProperties.getSecretKey()); | ||
} | ||
} | ||
return client; | ||
} | ||
|
||
@Override | ||
public void afterPropertiesSet() { | ||
client = getInstanceClient(); | ||
} | ||
|
||
@PreDestroy | ||
public void destroy() { | ||
this.client.shutdown(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.