我使用带模块的弹簧靴.我有一个包含多个子模块的父项目.
当我使用Contructor Autowiring配置路由时,Camel Routes无法启动.
我得到Total 0路由,其中0是启动时启动这样的构造函数.
private final ScanProcessor scanProcessor;
private final ScheduleProcessor scheduleProcessor;
private final TagProcessor tagProcessor;
private final LatestScanProcessor latestScanProcessor;
private final RabbitMqService rabbitMqService;
@Autowired
public DashboardRoute(ScanProcessor scanProcessor,ScheduleProcessor scheduleProcessor,TagProcessor tagProcessor,LatestScanProcessor latestScanProcessor,RabbitMqService rabbitMqService){
this.scanProcessor = scanProcessor;
this.scheduleProcessor = scheduleProcessor;
this.tagProcessor = tagProcessor;
this.latestScanProcessor = latestScanProcessor;
this.rabbitMqService = rabbitMqService;
}
@Override
public void configure() throws Exception {
from(CONSUME_SCHEDULE_ROUTE)
.routeId("consume-schedule")
.process(scheduleProcessor); // no strings
}
当我不对任何豆子进行自动装配并对这样的路线进行处理时,整个过程都有效.
from(CONSUME_SCHEDULE_ROUTE)
.routeId("consume-schedule")
.process("scheduleProcessor") // notice this is a string
骆驼是否支持弹簧路径Contructor自动装配?我是否需要采取一些额外的配置步骤才能正确处理?我更喜欢直接链接bean,当我重构它连接回来的类名时ok.
最佳答案
我尝试了与你相似的例子,它工作正常.您可以确保在路由类和所有处理器类和服务类中都有@Compoent.
原文链接:https://www.f2er.com/spring/431893.html您也可以尝试在局部变量上添加@Autowired. (构造函数应该可以正常工作.这只是确保构造函数工作的额外工具)
@Component
@ServletComponentScan(basePackages = "com.example.camel")
public class ServiceRoutes extends RouteBuilder {
@Autowired
private ScanProcessor scanProcessor;
@Autowired
private ScheduleProcessor scheduleProcessor;
@Autowired
private TagProcessor tagProcessor;
@Autowired
private LatestScanProcessor latestScanProcessor;
@Autowired
private RabbitMqService rabbitMqService;
@Override
public void configure() throws Exception {
from(CONSUME_SCHEDULE_ROUTE)
.routeId("consume-schedule")
.process(scheduleProcessor);
}
}
希望这可以帮助.