本文介绍了春季靴骆驼测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to test Camel routes in a Spring Boot Application.I've the Spring boot main class with all the necessary beans declared in it.I am using the CamelSpringJUnit4ClassRunner.class.Added my Spring boot main class in @ContextConfiguration as it contains all the configurations. I don't have a separate configuration class.

我已经在Test类中自动连接了CamelContext:

I 've autowired CamelContext in my Test class:

@Autowired
CamelContext camelContext;

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

But the test fails with the error:

没有可用的'org.apache.camel.CamelContext'类型的合格bean:期望至少有1个合格的autowire候选bean.

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

依赖项注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}

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

推荐答案

尝试使用CamelSpringBootRunner.class作为运行程序,并在测试类中添加@SpringBootTest批注.

Try to use the CamelSpringBootRunner.class as the runner and add the @SpringBootTest annotation to the test class.

示例

如果将引导程序类更改为SpringBootTestContextBootstrapper,则它应该起作用:

If you change your bootstrapper class to SpringBootTestContextBootstrapper then it should work:

@BootstrapWith(SpringBootTestContextBootstrapper.class)


与您相同的配置,但是在这种情况下,您无需添加ContextConfigurationBootstrapWith批注:


The equivalent configuration as you have but in this case you don't need to add the ContextConfiguration and the BootstrapWith annotation:

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

这篇关于春季靴骆驼测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 11:13