Sping Boot 3 + Spring cloud migration for S3 auto configure

8yoxcaq7  于 2023-05-27  发布在  Spring
关注(0)|答案(1)|浏览(107)

** Spring Boot 2.7.9**

<parent>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-parent</artifactId>
   <version>2.7.9</version>
   <relativePath /> <!-- lookup parent from repository -->
</parent>

这些Spring云依赖项

<dependency>
    <groupId>io.awspring.cloud</groupId>
    <artifactId>spring-cloud-aws-context</artifactId>
    <version>2.4.2</version>
</dependency>
<dependency>
    <groupId>io.awspring.cloud</groupId>
    <artifactId>spring-cloud-aws-autoconfigure</artifactId>
    <version>2.4.2</version>
</dependency>
<dependency>
    <groupId>io.awspring.cloud</groupId>
    <artifactId>spring-cloud-starter-aws-secrets-manager-config</artifactId>
    <version>2.4.2</version>
</dependency>

属性条目

cloud.aws.region.static=us-east-2
cloud.aws.region.auto=false
cloud.aws.stack.auto=false

服务器引导没有任何问题

** Spring Boot 3.0.2**

<parent>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-parent</artifactId>
   <version>3.0.2</version>
   <relativePath />
</parent>
<dependency>
    <groupId>io.awspring.cloud</groupId>
    <artifactId>spring-cloud-aws-context</artifactId>
    <version>2.4.4</version>
</dependency>
<dependency>
    <groupId>io.awspring.cloud</groupId>
    <artifactId>spring-cloud-aws-autoconfigure</artifactId>
    <version>2.4.4</version>
</dependency>
<dependency>
    <groupId>io.awspring.cloud</groupId>
    <artifactId>spring-cloud-starter-aws-secrets-manager-config</artifactId>
    <version>2.4.4</version>
</dependency>

服务器因错误而停止

Field amazonS3Client in com.test.S3BucketStorageServiceImpl required a bean of type 'com.amazonaws.services.s3.AmazonS3' that could not be found. The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true) 
Action: Consider defining a bean of type 'com.amazonaws.services.s3.AmazonS3' in your configuration.

我的问题:属性文件密钥名称是否已更改?

koaltpgm

koaltpgm1#

自动配置不起作用,因此我必须手动创建Bean

import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class MyS3Config {
    @Bean
    public AmazonS3 getS3Client() {
        return AmazonS3ClientBuilder.defaultClient();
    }
}

这解决了问题

相关问题