springamazon-web-servicesspring-cloudspring-cloud-aws

Spring boot 3 + Spring cloud migration for S3 auto configure


For 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>

These spring cloud dependencies

<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>

Properties entry

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

Server boots without any problem

For 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>

Server stop with error

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.

My Question: is the property file key names got changed ?


Solution

  • Automatic configuration not working, Therefore I have to manually create a 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();
        }
    }
    

    this solves the problem