Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 792
Jardo Avatar asked Feb 19 '19 16:02

Jardo


1 Answers

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);
    }

}
like image 179
Matthias Bohlen Avatar answered Oct 09 '22 04:10

Matthias Bohlen