首页 文章

Spring Boot Camel测试

提问于
浏览
0

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

我在我的Test类中自动安装了CamelContext:

@Autowired
CamelContext camelContext;

但测试失败并出现错误:

引起:org.springframework.beans.factory.NoSuchBeanDefinitionException:没有类型为'org.apache.camel.CamelContext'的限定bean可用:预计至少有1个bean可以作为autowire候选者 . 依赖注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}

1 回答

  • 4

    尝试使用 CamelSpringBootRunner.class 作为跑步者并将 @SpringBootTest 注释添加到测试类 .

    来自Camel存储库的Example

    更新(根据您的评论)

    如果您将引导程序类更改为 SpringBootTestContextBootstrapper ,那么它应该工作:

    @BootstrapWith(SpringBootTestContextBootstrapper.class)
    

    与您相同的配置,但在这种情况下,您不需要添加 ContextConfigurationBootstrapWith 注释:

    @RunWith(CamelSpringBootRunner.class)
    @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
    @MockEndpoints("log:*")
    @DisableJmx(false)
    @SpringBootTest(classes = MyClass.class)
    

相关问题