[英]Spring Boot + Quartz: "Requested bean is currently in creation: Is there an unresolvable circular reference?"
[英]Spring unresolvable circular reference Quartz
@Autowired
private ApplicationContext applicationContext;
@Autowired
private Scheduler scheduler;
public static void main(String[] args) {
SpringApplication.run(SchedulingApplication.class, args);
}
@PostConstruct
public void init() {
try {
this.scheduler.start();
} catch (SchedulerException e) {
LOGGER.error("Failed to start scheduler");
}
}
@Bean
@Autowired
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) {
SchedulerFactoryBean bean = new SchedulerFactoryBean();
bean.setDataSource(dataSource);
bean.setApplicationContext(applicationContext);
bean.setAutoStartup(true);
bean.setConfigLocation(new ClassPathResource("/config/quartz.properties"));
AutowiringSpringBeanJobFactory jobFactory = new AutowiringSpringBeanJobFactory();
jobFactory.setApplicationContext(applicationContext);
bean.setJobFactory(jobFactory);
return bean;
}
創建名稱為'schedulerFactoryBean'的bean時出錯:當前正在創建請求的bean:是否存在無法解析的循環引用?
適用於Spring Boot 1.2.3,不適用於最新的1.3.2。
SchedulerFactoryBean用於創建Scheduler的實例。 在您的配置中,Spring嘗試在執行@Bean方法之前(因此在創建SchedulerFactoryBean之前)注入Scheduler。 那就是為什么您得到例外。 如果將其拆分,則使用SchedulerFactoryBean進行的一種配置以及使用Scheduler進行的另一種配置都應該起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.