Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camel No Route when Autowiring Constructor

Im using spring boot with modules. I have a parent project with several sub modules.

Camel Routes are failing to start up when I configure the route with Contructor Autowiring.

I get Total 0 routes, of which 0 are startedWhen starting constructor like this.

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
}

The whole thing works when I dont autowire any of the beans and delcare the route like this.

 from(CONSUME_SCHEDULE_ROUTE)
   .routeId("consume-schedule")
   .process("scheduleProcessor")  // notice this is a string

Does camel support spring route Contructor autowiring? Do I need to take some extra config steps to handle this properly? I prefer linking beans directly that way when I refactor class names it links back ok.

like image 859
Robbo_UK Avatar asked Apr 10 '18 12:04

Robbo_UK


Video Answer


1 Answers

I tried similar example as yours and it worked correctly. You can make sure that you have @Compoent in you route class and all the processor classes and service class.

Also you can try to add @Autowired on the local variable. (Constructor should work fine. This is just an extra stap to make sure your constructor works)

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

Hope this helps.

like image 191
Reedwanul Islam Avatar answered Sep 24 '22 18:09

Reedwanul Islam