Spring Boot camel集成测试,CamelContext自动连线失败

ercv8c1e  于 2022-11-07  发布在  Apache
关注(0)|答案(1)|浏览(290)

我正在为Camel路由编写单元测试。我需要使用@SpringBootTest,以便我也可以使用@TestPropertySource。我有几个Map属性类的属性文件。
我的测试代码如下所示

@SpringBootTest(classes = {CamelAutoConfiguration.class})
@RunWith(CamelSpringBootRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@ActiveProfiles("test")
@TestPropertySource(locations = "classpath:application-test.yml")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@ContextConfiguration(classes = {ApplicationConfig.class, SFTPConfig.class, CamelTestContextBootstrapper.class})
@EnableConfigurationProperties
public class RouteBuilderTest
{

    @Autowired
    private CamelContext camelContext;

我在项目中使用junit 4时也添加了以下依赖项。

<dependency>
     <groupId>org.apache.camel</groupId>
     <artifactId>camel-test-spring</artifactId>
     <scope>test</scope>
</dependency>

CamelContext的自动配置失败。出现标准Spring错误。

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)}

请帮帮忙。我被这个卡住了。

n6lpvg4x

n6lpvg4x1#

您的测试中有多个误用的注解。请尝试以下方法:

@RunWith(CamelSpringBootRunner.class)
@SpringBootTest(classes = {ApplicationConfig.class, SFTPConfig.class})
@ActiveProfiles("test")
@TestPropertySource(locations = "classpath:application-test.yml")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class RouteBuilderTest
{
    @Autowired
    private CamelContext camelContext;

相关问题