1

I'm try to use S3Client from AWS Java SDK v2, on my JHipster Spring boot project.

In addition to S3CLient i'm using S3Presigner for pre-signed url generation.

This is the configuration class, that i'm using to create beans:

@Configuration
public class AWSConfiguration {

    private final Logger log = LoggerFactory.getLogger(AWSConfiguration.class);

    @Bean(name = "credentialsProvider")
    public AwsCredentialsProvider getCredentialsProvider(@Value("${aws.accessKey}") String accessKey, @Value("${aws.secretKey}") String secretKey) {
        return StaticCredentialsProvider.create(AwsBasicCredentials.create(accessKey, secretKey));
    }

    @Bean(name = "presigner")
    @Primary
    public S3Presigner getPresigner(@Value("${aws.region}") String awsRegion, @Qualifier("credentialsProvider") final AwsCredentialsProvider credentialsProvider) {
        return S3Presigner.builder().credentialsProvider(credentialsProvider).region(Region.of(awsRegion)).build();
    }

    @Bean(name = "s3Client")
    @Primary
    public S3Client getS3Client(@Value("${aws.region}") String awsRegion, @Qualifier("credentialsProvider") final AwsCredentialsProvider credentialsProvider) {
        return S3Client.builder().credentialsProvider(credentialsProvider).region(Region.of(awsRegion)).build();
    }

}

At the boot, i've this error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 's3Client' defined in class path resource [com/cyd/bb/config/AWSConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [software.amazon.awssdk.services.s3.S3Client]: Factory method 'getS3Client' threw exception; nested exception is java.lang.IllegalArgumentException: Expected a profile or property definition on line 1

If i remove "s3Client" bean the project start correctly and i can use presigner without problems.

So s3Client produce the error, someone can help me for this issue?

Thanks in advance.

0 Answers0