Jardo
Jardo

Reputation: 2093

Turning off Spring Boot AWS Autoconfiguration

I'm using spring-cloud-aws-autoconfigure:2.1.0.RELEASE to connect to AWS. However when the app is running in an enviromnent other than AWS, I don't want the auto configuration to take place.

I tried turning off the auto configuration as suggested here and here with java configuration class, and also with spring.autoconfigure.excludes property in my yml file like this:

spring:
  autoconfigure:
    exclude:
      - org.springframework.cloud.aws.autoconfigure.context.ContextCredentialsAutoConfiguration
      - org.springframework.cloud.aws.autoconfigure.context.ContextInstanceDataAutoConfiguration
      - org.springframework.cloud.aws.autoconfigure.context.ContextStackAutoConfiguration
      - org.springframework.cloud.aws.autoconfigure.messaging.MessagingAutoConfiguration

But none of those solutions seems to work. The autoconfiguration still takes place and consequently, the app fails to start.

Upvotes: 6

Views: 9309

Answers (2)

Matthias Bohlen
Matthias Bohlen

Reputation: 668

Found a solution: I added this directly to my main application class:

import org.springframework.cloud.aws.autoconfigure.context.*;

@SpringBootApplication
@EnableAutoConfiguration(exclude = {
        ContextCredentialsAutoConfiguration.class,
        ContextInstanceDataAutoConfiguration.class,
        ContextRegionProviderAutoConfiguration.class,
        ContextResourceLoaderAutoConfiguration.class,
        ContextStackAutoConfiguration.class,
        MailSenderAutoConfiguration.class,
})
public class MyApplication {

    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }

}

Upvotes: 7

Jardo
Jardo

Reputation: 2093

Found solution: I excluded every class I found in the autoconfiguration jar:

spring:
  autoconfigure:
    exclude:
      - org.springframework.cloud.aws.autoconfigure.cache.ElastiCacheAutoConfiguration
      - org.springframework.cloud.aws.autoconfigure.context.ContextCredentialsAutoConfiguration
      - org.springframework.cloud.aws.autoconfigure.context.ContextInstanceDataAutoConfiguration
      - org.springframework.cloud.aws.autoconfigure.context.ContextRegionProviderAutoConfiguration
      - org.springframework.cloud.aws.autoconfigure.context.ContextRegionProviderAutoConfiguration
      - org.springframework.cloud.aws.autoconfigure.context.ContextRegionProviderAutoConfiguration
      - org.springframework.cloud.aws.autoconfigure.jdbc.AmazonRdsDatabaseAutoConfiguration
      - org.springframework.cloud.aws.autoconfigure.mail.MailSenderAutoConfiguration
      - org.springframework.cloud.aws.autoconfigure.messaging.MessagingAutoConfiguration
      - org.springframework.cloud.aws.autoconfigure.metrics.CloudWatchExportAutoConfiguration

Upvotes: 4

Related Questions