I have my main Application annotated with @SpringBootApplication. Here is the code for the following:
@SpringBootApplication
public class Application {
private Logger logger = LoggerFactory.getLogger(Application.class);
@Autowired
public ExternalConfiguration configuration;
@Autowired
WorkerThread workerThread;
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(new Object[] { Application.class });
springApplication.run(args);
}
}
And here is my WorkerThread.java
@Component
@Scope("prototype")
public class WorkerThread implements Runnable {
@Autowired
private ApplicationContext applicationContext;
@Autowired
ExternalConfiguration externalConfiguration;
@Autowired
WorkerConfig workerConfig;
WorkerQueueDispatcher dispatcher;
public WorkerThread() {
dispatcher = applicationContext.getBean(WorkerQueueDispatcher.class, externalConfiguration.getEventQ(),
workerConfig.getWorkers());
}
@Override
public void run() {
logger.info("Worker thread started. Thread ID :" + Thread.currentThread().getId());
dispatcher.run();
}
}
I tried debugging and found out that my ApplicationContext was not getting Autowired and is null.
I haven't used new for instantiating the WorkerThread.
Please help me.