java – 自动装配构造函数时没有路径的Camel

前端之家收集整理的这篇文章主要介绍了java – 自动装配构造函数时没有路径的Camel前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我使用带模块的弹簧靴.我有一个包含多个子模块的父项目.

当我使用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.

您也可以尝试在局部变量上添加@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); 
    }
}

希望这可以帮助.

原文链接:https://www.f2er.com/spring/431893.html

猜你在找的Spring相关文章