繁体   English   中英

在使用Apache Camel进行Spring Boot应用程序的单元测试中,无法将@Component作为Bean获得

[英]Can Not Get @Component As A Bean In Unit Test For Spring Boot Application with Apache Camel

我正在使用Camel对我的Spring Boot应用程序进行单元测试。 当应用程序运行时,它可以获取配置为@Component的bean。

@Component("agencyExporterProcessor")
public class AgencyExporterProcessor {}

我得到这样的豆:

 from(getTriggerExportEndpoint())
            .routeId(getTriggerExportId())
            // When shutting down, Camel will wait until the batch completed
            .shutdownRunningTask(ShutdownRunningTask.CompleteAllTasks)
            .log("[SamCustomExporter] - RouteId:${routeId} - Begin at ${date:now:MM/dd/yyyy HH:mm:ss.SSS}")
            .setHeader(Messaging.Names.SAM_DATA_AGENCY_CONFIGURATION_HEADER_KEY.toString(), constant(getConfiguration()))

            // Initialize a list to store exported CSV file names
            .bean(agencyExporterProcessor, "prepareExportedFileList")

但是当我测试时,路线无法得到bean”

org.apache.camel.FailedToCreateRouteException: Failed to create route agencyExporterRoute_triggerExport at: >>> Bean[ref:agencyExporterProcessor method:prepareExportedFileList] <<< in route: Route(agencyExporterRoute_triggerExport)[[From[direct:agency... because of No bean could be found in the registry for: agencyExporterProcessor

这是我配置单元测试类的方式:

@DirtiesContext
@RunWith(SpringRunner.class)
@EnableAutoConfiguration
@SpringBootApplication
@SpringBootTest(classes = SamCustomExporterSpringApplication.class, 
webEnvironment = SpringBootTest.WebEnvironment.NONE)
public class AgencyExporterRouteTest extends BaseRouteTestSupport {}

请指教!!!! 非常感谢

您应该在Camel路由中将bean名称引用为String值:

.bean("agencyExporterProcessor", "prepareExportedFileList")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM