|
@@ -28,27 +28,31 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
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.context.annotation.Primary;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author Xiewj
|
|
* @author Xiewj
|
|
* @date 2023/8/28
|
|
* @date 2023/8/28
|
|
*/
|
|
*/
|
|
@Configuration
|
|
@Configuration
|
|
-@EnableConfigurationProperties({AliyunOssProperties.class, AwsProperties.class, CosProperties.class, MinioProperties.class})
|
|
|
|
@ConditionalOnProperty(prefix = "filestorage",name= "active")
|
|
@ConditionalOnProperty(prefix = "filestorage",name= "active")
|
|
public class StorageAutoConfiguration {
|
|
public class StorageAutoConfiguration {
|
|
|
|
+
|
|
@Bean
|
|
@Bean
|
|
@ConditionalOnProperty(name = "filestorage.active",havingValue = "oss")
|
|
@ConditionalOnProperty(name = "filestorage.active",havingValue = "oss")
|
|
|
|
+ public AliyunOssProperties aliyunOssProperties(){
|
|
|
|
+ return new AliyunOssProperties();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Bean(name = "aliyunOssClient")
|
|
|
|
+ @ConditionalOnProperty(name = "filestorage.active",havingValue = "oss")
|
|
public OSS aliyunOssClient(AliyunOssProperties properties) {
|
|
public OSS aliyunOssClient(AliyunOssProperties properties) {
|
|
return new OSSClientBuilder().build(properties.getRequestEndpoint(),
|
|
return new OSSClientBuilder().build(properties.getRequestEndpoint(),
|
|
properties.getAccessKey(),
|
|
properties.getAccessKey(),
|
|
properties.getAccessKeySecret(),
|
|
properties.getAccessKeySecret(),
|
|
properties.getConfig());
|
|
properties.getConfig());
|
|
}
|
|
}
|
|
- @Bean
|
|
|
|
|
|
+ @Bean(name = "aliyunOssTemplate")
|
|
@Qualifier("oss")
|
|
@Qualifier("oss")
|
|
- @Primary
|
|
|
|
@ConditionalOnProperty(name = "filestorage.active",havingValue = "oss")
|
|
@ConditionalOnProperty(name = "filestorage.active",havingValue = "oss")
|
|
public FileStorageTemplate aliyunOssTemplate(OSS oss, AliyunOssProperties properties) {
|
|
public FileStorageTemplate aliyunOssTemplate(OSS oss, AliyunOssProperties properties) {
|
|
return new AliyunOssTemplate(oss, properties);
|
|
return new AliyunOssTemplate(oss, properties);
|
|
@@ -57,6 +61,13 @@ public class StorageAutoConfiguration {
|
|
|
|
|
|
@Bean
|
|
@Bean
|
|
@ConditionalOnProperty(name = "filestorage.active",havingValue = "awss3")
|
|
@ConditionalOnProperty(name = "filestorage.active",havingValue = "awss3")
|
|
|
|
+ public AwsProperties awsProperties(){
|
|
|
|
+ return new AwsProperties();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Bean(name = "amazonS3Client")
|
|
|
|
+ @ConditionalOnProperty(name = "filestorage.active",havingValue = "awss3")
|
|
public AmazonS3 amazonS3Client(AwsProperties properties) {
|
|
public AmazonS3 amazonS3Client(AwsProperties properties) {
|
|
BasicAWSCredentials awsCreds = new BasicAWSCredentials(properties.getAccessKey(), properties.getAccessKeySecret());
|
|
BasicAWSCredentials awsCreds = new BasicAWSCredentials(properties.getAccessKey(), properties.getAccessKeySecret());
|
|
ClientConfiguration clientConfiguration = new ClientConfiguration();
|
|
ClientConfiguration clientConfiguration = new ClientConfiguration();
|
|
@@ -72,15 +83,22 @@ public class StorageAutoConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- @Bean
|
|
|
|
|
|
+ @Bean(name = "AwsOssTemplate")
|
|
@Qualifier("awss3")
|
|
@Qualifier("awss3")
|
|
@ConditionalOnProperty(name = "filestorage.active",havingValue = "awss3")
|
|
@ConditionalOnProperty(name = "filestorage.active",havingValue = "awss3")
|
|
public FileStorageTemplate AwsOssTemplate(AmazonS3 oss, AwsProperties properties) {
|
|
public FileStorageTemplate AwsOssTemplate(AmazonS3 oss, AwsProperties properties) {
|
|
return new AwsTemplate(oss, properties);
|
|
return new AwsTemplate(oss, properties);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
@Bean
|
|
@Bean
|
|
@ConditionalOnProperty(name = "filestorage.active",havingValue = "cos")
|
|
@ConditionalOnProperty(name = "filestorage.active",havingValue = "cos")
|
|
|
|
+ public CosProperties cosProperties(){
|
|
|
|
+ return new CosProperties();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Bean(name = "cosClient")
|
|
|
|
+ @ConditionalOnProperty(name = "filestorage.active",havingValue = "cos")
|
|
public COSClient cosClient(CosProperties properties) {
|
|
public COSClient cosClient(CosProperties properties) {
|
|
|
|
|
|
// 1 初始化用户身份信息(secretId, secretKey)。
|
|
// 1 初始化用户身份信息(secretId, secretKey)。
|
|
@@ -102,23 +120,30 @@ public class StorageAutoConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- @Bean
|
|
|
|
|
|
+ @Bean(name = "cosTemplate")
|
|
@Qualifier("cos")
|
|
@Qualifier("cos")
|
|
@ConditionalOnProperty(name = "filestorage.active",havingValue = "cos")
|
|
@ConditionalOnProperty(name = "filestorage.active",havingValue = "cos")
|
|
- public FileStorageTemplate cosTemplate(COSClient ossClient, CosProperties properties) {
|
|
|
|
- return new CosTemplate(ossClient, properties);
|
|
|
|
|
|
+ public FileStorageTemplate cosTemplate(COSClient ossClient, CosProperties cosProperties) {
|
|
|
|
+ return new CosTemplate(ossClient, cosProperties);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
@Bean
|
|
@Bean
|
|
|
|
+ @ConditionalOnProperty(name = "filestorage.active",havingValue = "cos")
|
|
|
|
+ public MinioProperties minioProperties(){
|
|
|
|
+ return new MinioProperties();
|
|
|
|
+ }
|
|
|
|
+ @Bean(name = "minioClient")
|
|
@ConditionalOnProperty(name = "filestorage.active",havingValue = "minio")
|
|
@ConditionalOnProperty(name = "filestorage.active",havingValue = "minio")
|
|
- public MinioClient minioClient(MinioProperties properties) {
|
|
|
|
|
|
+ public MinioClient minioClient(MinioProperties minioProperties) {
|
|
return MinioClient.builder()
|
|
return MinioClient.builder()
|
|
- .endpoint(properties.getEndpoint())
|
|
|
|
- .credentials(properties.getAccessKey(), properties.getAccessKeySecret())
|
|
|
|
|
|
+ .endpoint(minioProperties.getEndpoint())
|
|
|
|
+ .credentials(minioProperties.getAccessKey(), minioProperties.getAccessKeySecret())
|
|
.build();
|
|
.build();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- @Bean
|
|
|
|
|
|
+ @Bean(name = "minioOssTemplate")
|
|
@Qualifier("minio")
|
|
@Qualifier("minio")
|
|
@ConditionalOnProperty(name = "filestorage.active",havingValue = "minio")
|
|
@ConditionalOnProperty(name = "filestorage.active",havingValue = "minio")
|
|
public FileStorageTemplate minioOssTemplate(MinioClient oss, MinioProperties properties) {
|
|
public FileStorageTemplate minioOssTemplate(MinioClient oss, MinioProperties properties) {
|