Search code examples
javaspringspring-cloudspring-cloud-aws

Where does Spring Cloud AWS 2.x auto-configure the AmazonS3 bean?


I'm currently running into the well-known startup failure where Spring Cloud AWS is attempting to create an AmazonS3 bean but doesn't have a region defined. In a particular profile, I do not want Spring Cloud AWS to activate anything at all. I have successfully suppressed SNS and SQS with cloud.aws.{sns,sqs}.enabled=false, but I can't find where the AmazonWebserviceClientFactoryBean<AmazonS3> is injected into the context; debugging the constructor shows it's being lazily created from a bean definition.

What code in Spring Cloud AWS auto-configures the bean for the AmazonS3 client?


Solution

  • The ContextResourceLoaderAutoConfiguration class indirectly imports ContextResourceLoaderConfiguration.Registrar, which has a hard-coded bean registration for an AmazonS3Client buried inside it. Neither the registrar nor the auto-configuration class supports the usual well-behaved property conditions to disable S3 client creation (e.g., cloud.aws.{s3,loader}.enabled=false).

    In order to suppress creation of the S3 client (which is unconditional), the ContextResourceLoaderAutoConfiguration class must be listed in the exclude parameter of the @EnableAutoConfiguration or @SpringBootApplication annotation.