2017-10-17 71 views
1

我正在为使用Camel的Spring Boot应用程序进行单元测试。当应用程序运行时,它可以得到被配置为@Component无法获取@Component作为Bean在单元测试中使用Apache Camel进行Spring Boot应用程序

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

豆,我得到这个bean是这样的:

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

但是当我测试,路线不能得到豆”

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

请给意见!!!!非常感谢

回答

0

你应该参考这个bean名称,如骆驼路线String值:

.bean("agencyExporterProcessor", "prepareExportedFileList") 
+0

对不起,这是我的错误,当我复制的代码。是的,我确实喜欢你,易卜生先生。但它仍然有这个错误 –

+0

基本包应该是相同的组件扫描。两个课程的包装位置是什么? – priyas

相关问题