【发布时间】:2020-01-09 17:39:08
【问题描述】:
我正在使用一个名为 spring-cloud-aws 的依赖模块。它有一个 @Configuration 类作为 org.springframework.cloud.aws.messaging.config.annotation.SqsConfiguration 在我的 SpringBoot JUnit 测试用例中,检测到 SqsConfiguration 类并初始化 Bean。我想在我的 JUNit 测试用例中排除这个配置。如何做到这一点?
我尝试使用@ComponentScan,但它不起作用。
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SQLTestConfig.class)
@ActiveProfiles("test")
public class BusinessManagerTest {
}
@TestConfiguration
@ComponentScan(basePackages = {"package1","package1"},
excludeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = SqsConfiguration.class)})
@Profile("test")
class SQLTestConfig {
@Bean
public SomeBean beans() {
return new SomeBean();
}
}
加载此配置类需要可用的 aws 凭据。我不想注入凭据来运行一个简单的 Bean 测试用例。
org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/cloud/aws/messaging/config/annotation/SqsConfiguration.class] 中定义名称为“simpleMessageListenerContainer”的 bean 创建错误:调用 init 方法失败的;嵌套异常是 com.amazonaws.services.sqs.model.AmazonSQSException: 请求中包含的安全令牌已过期
【问题讨论】:
标签: spring-boot spring-cloud-aws