OSS学习笔记-SpringBoot集成阿里云配置

1、依赖包导入



    com.aliyun.oss
    aliyun-sdk-oss
    3.16.0

2、自动配置引入

@Getter
@Setter
@Component("aliYunOssProperties")
@ConfigurationProperties(prefix = "aliyun.oss")
public class AliYunOssProperties {

    /** AccessKeyID */
    private String accessKeyId = null;

    /** AccessKeySecret */
    private String accessKeySecret = null;

    /** 域名 */
    private String domain;

    /** PRODUCT */
    private String product = "Sts";

    /** 阿里云节点 */
    private String endpoint;

    /** Region ID */
    private String regionId;

    /** RoleArn */
    private String roleArn;

    /** 持续时间(秒) */
    private Long duration = 300L;

    /** 桶名 */
    private String bucket;

}
@BeanComponentScan(basePackages = { Constants.SERVICE_PACKAGE }, annotationClass = Service.class)
@EnableConfigurationProperties({ AliYunOssProperties.class })
@Configuration
public class AliYunOssAutoConfiguration {

    @Bean
    public OSS aliYunOssClient(AliYunOssProperties aliYunOssProperties) {
        return new OSSClientBuilder().build(aliYunOssProperties.getEndpoint(),
            aliYunOssProperties.getAccessKeyId(), aliYunOssProperties.getAccessKeySecret());
    }

    @Bean
    public IAcsClient aliYunOssAcsClient(AliYunOssProperties aliYunAcsClientSmsProperties) {
        IClientProfile profile= DefaultProfile.getProfile(aliYunAcsClientSmsProperties.getRegio

你可能感兴趣的:(J2EE,spring,boot,阿里云,oss,java)