org.zodiac.autoconfigure.oss.PlatformAliOssAutoConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.oss;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.zodiac.autoconfigure.oss.condition.ConditionalOnOssEnabled;
import org.zodiac.autoconfigure.security.condition.ConditionalOnSecurityHttpEnabled;
/**
* Alioss配置类。
*
*/
@SpringBootConfiguration
@ConditionalOnOssEnabled
//@ConditionalOnWebApplication
@ConditionalOnSecurityHttpEnabled
@AutoConfigureAfter(value = {PlatformOssAutoConfiguration.class})
@ConditionalOnClass(value = {com.aliyun.oss.OSSClient.class, org.zodiac.oss.config.PlatformOssInfo.class})
@ConditionalOnProperty(value = org.zodiac.oss.constants.OssSystemPropertiesConstants.PLATFORM_OSS_NAME, havingValue = org.zodiac.oss.constants.OssConstants.ALI_OSS)
public class PlatformAliOssAutoConfiguration {
private final PlatformOssProperties ossProperties;
private final org.zodiac.oss.rule.OssRule ossRule;
public PlatformAliOssAutoConfiguration(PlatformOssProperties ossProperties, org.zodiac.oss.rule.OssRule ossRule) {
this.ossProperties = ossProperties;
this.ossRule = ossRule;
}
@Bean
@ConditionalOnMissingBean
protected com.aliyun.oss.OSSClient ossClient() {
/*创建ClientConfiguration。ClientConfiguration是OSSClient的配置类,可配置代理、连接超时、最大连接数等参数。*/
com.aliyun.oss.ClientConfiguration conf = new com.aliyun.oss.ClientConfiguration();
org.zodiac.oss.config.AliOssInfo aliOss = ossProperties.getAlioss();
conf.setMaxConnections(aliOss.getMaxConnections());
conf.setSocketTimeout(aliOss.getSocketTimeout());
conf.setConnectionTimeout(aliOss.getConnectionTimeout());
conf.setConnectionRequestTimeout(aliOss.getConnectionRequestTimeout());
conf.setIdleConnectionTime(aliOss.getIdleConnectionTime());
conf.setMaxErrorRetry(aliOss.getMaxErrorRetry());
conf.setConnectionTTL(aliOss.getConnectionTTL());
conf.setUseReaper(aliOss.isUseReaper());
conf.setRequestTimeout(aliOss.getRequestTimeout());
conf.setSlowRequestsThreshold(aliOss.getSlowRequestsThreshold());
com.aliyun.oss.common.auth.CredentialsProvider credentialsProvider =
new com.aliyun.oss.common.auth.DefaultCredentialProvider(ossProperties.getAccessKey(), ossProperties.getSecretKey());
return new com.aliyun.oss.OSSClient(ossProperties.getEndpoint(), credentialsProvider, conf);
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(value = {com.aliyun.oss.OSSClient.class})
protected org.zodiac.oss.AliossTemplate aliossTemplate(com.aliyun.oss.OSSClient ossClient) {
return new org.zodiac.oss.AliossTemplate(ossClient, ossProperties, ossRule);
}
}