我正在使用spring-cloud-aws-autoconfigure:2.1.0.RELEASE
连接到AWS。但是,当应用程序在非AWS的环境中运行时,我不希望进行自动配置。
我尝试使用Java配置类以及yml文件中的spring.autoconfigure.excludes
属性按照建议的here和here关闭自动配置,如下所示:
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
但是这些解决方案似乎都不起作用。自动配置仍然会发生,因此应用程序无法启动。
答案 0 :(得分:3)
找到了一个解决方案:我将其直接添加到我的主应用程序类中:
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);
}
}
答案 1 :(得分:0)
找到的解决方案:我排除了在自动配置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
答案 2 :(得分:0)
您是使用Maven还是Gradle进行构建。如果是行家,已经有这个问题的答案
Disable Spring Cloud AWS autoconfiguration for local development