gpt4 book ai didi

spring-boot - Spring Boot Camel 测试

转载 作者:行者123 更新时间:2023-12-03 18:38:03 26 4
gpt4 key购买 nike

我需要在 Spring Boot 应用程序中测试 Camel 路由。
我有 Spring boot 主类,其中声明了所有必需的 bean。
我正在使用 CamelSpringJUnit4ClassRunner.class。
在 @ContextConfiguration 中添加了我的 Spring boot 主类,因为它包含所有配置。我没有单独的配置类。

我在我的测试类中 Autowiring 了 CamelContext:

@Autowired
CamelContext camelContext;

但是测试失败并显示错误:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:

No qualifying bean of type 'org.apache.camel.CamelContext' available: expected at least 1 bean which qualifies as autowire candidate.

Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

最佳答案

尝试使用 CamelSpringBootRunner.class 作为运行器,并在测试类中添加 @SpringBootTest 注释。

来自 Camel 存储库的 Example

更新(根据您的评论)

如果您将 bootstrap 类更改为 SpringBootTestContextBootstrapper,那么它应该可以工作:

@BootstrapWith(SpringBootTestContextBootstrapper.class)

与您拥有的等效配置,但在这种情况下,您不需要添加 ContextConfigurationBootstrapWith 注释:
@RunWith(CamelSpringBootRunner.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@MockEndpoints("log:*")
@DisableJmx(false)
@SpringBootTest(classes = MyClass.class)

关于spring-boot - Spring Boot Camel 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45874617/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com