0
Good morning,
I have a component that has injected services. This component is of the 'prototype' scope and is running infinitely. I need to run X components (passed via argument) of these and why I would like to use @Autowired List
But how to do this? How to exchange the 4 crawlers for a List?
@Component
@Scope("prototype")
public class Crawler implements Runnable {
@Autowired private PaginaService service;
@Autowired private StatusService statusService;
@Override
public void run() {
// while loop infinito
}
}
@Configuration
public class CrawlerExecutor {
@Autowired private Crawler crawler1;
@Autowired private Crawler crawler2;
@Autowired private Crawler crawler3;
@Autowired private Crawler crawler4;
@Bean
public TaskExecutor executor() {
return new SimpleAsyncTaskExecutor();
}
@Bean
public CommandLineRunner runner(TaskExecutor executor) {
return new CommandLineRunner() {
@Override
public void run(String... args) throws Exception {
executor.execute(crawler1);
executor.execute(crawler2);
executor.execute(crawler3);
executor.execute(crawler4);
}
};
}
}
Thanks!