Mit*_*tal 4 apache-camel spring-boot junit5 camel-test
我需要在 Spring Boot 应用程序中测试 Camel 路由。我有 Spring boot 主类,其中声明了所有必需的 bean。我正在使用 CamelSpringJUnit4ClassRunner.class。在 @ContextConfiguration 中添加了我的 Spring boot 主类,因为它包含所有配置。我没有单独的配置类。
我在我的测试类中自动装配了 CamelContext:
@Autowired
CamelContext camelContext;
Run Code Online (Sandbox Code Playgroud)
但是测试失败并显示错误:
引起:org.springframework.beans.factory.NoSuchBeanDefinitionException:
没有可用的“org.apache.camel.CamelContext”类型的合格 bean:预计至少有 1 个 bean 有资格作为自动装配候选。
依赖注解:{@org.springframework.beans.factory.annotation.Autowired(required=true)}
尝试将CamelSpringBootRunner.class
用作运行程序并将@SpringBootTest
注释添加到测试类中。
来自 Camel 存储库的示例
如果您将引导程序类更改为SpringBootTestContextBootstrapper
那么它应该可以工作:
@BootstrapWith(SpringBootTestContextBootstrapper.class)
Run Code Online (Sandbox Code Playgroud)
与您拥有的等效配置,但在这种情况下,您不需要添加ContextConfiguration
和BootstrapWith
注释:
@RunWith(CamelSpringBootRunner.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@MockEndpoints("log:*")
@DisableJmx(false)
@SpringBootTest(classes = MyClass.class)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5977 次 |
最近记录: |