【问题标题】:Turning off Spring Boot AWS Autoconfiguration关闭 Spring Boot AWS 自动配置
【发布时间】:2019-07-13 05:05:51
【问题描述】:

我正在使用 spring-cloud-aws-autoconfigure:2.1.0.RELEASE 连接到 AWS。但是,当应用程序在 AWS 以外的环境中运行时,我不希望进行自动配置。

我尝试使用 java 配置类按照建议的 herehere 以及我的 yml 文件中的 spring.autoconfigure.excludes 属性关闭自动配置,如下所示:

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

但这些解决方案似乎都不起作用。自动配置仍然发生,因此应用程序无法启动。

【问题讨论】:

    标签: java spring-boot spring-cloud-aws


    【解决方案1】:

    找到了解决方案:我将它直接添加到我的主应用程序类中:

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

    【讨论】:

      【解决方案2】:

      找到的解决方案:我排除了在自动配置 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
      

      【讨论】:

        【解决方案3】:

        您是使用 Maven 还是 Gradle 来构建。如果它是 maven,那么这个问题已经有了答案

        Disable Spring Cloud AWS autoconfiguration for local development

        【讨论】:

          猜你喜欢
          • 2021-07-19
          • 2017-01-19
          • 2018-09-09
          • 2018-09-06
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-05-03
          • 1970-01-01
          相关资源
          最近更新 更多