该作业工作正常,但每次运行该应用程序时,它都会给出一些警告消息:
[main] WARN o.s.b.f.s.DefaultListableBeanFactory - Bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'testJobBean': Requested bean is currently in creation: Is there an unresolvable circular reference?
[main] WARN o.s.b.f.s.DefaultListableBeanFactory - Bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'testJobBean': Requested bean is currently in creation: Is there an unresolvable circular reference?
[main] WARN o.s.b.f.s.DefaultListableBeanFactory - Bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'testJobBean': Requested bean is currently in creation: Is there an unresolvable circular reference?
[main] WARN o.s.b.f.s.DefaultListableBeanFactory - Bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'testJobBean': Requested bean is currently in creation: Is there an unresolvable circular reference?
[main] WARN o.s.b.f.s.DefaultListableBeanFactory - Bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'testJobBean': Requested bean is currently in creation: Is there an unresolvable circular reference?
[main] WARN o.s.b.f.s.DefaultListableBeanFactory - Bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'testJobBean': Requested bean is currently in creation: Is there an unresolvable circular reference?
[main] WARN o.s.b.f.s.DefaultListableBeanFactory - Bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'testJobBeanTrigger': Requested bean is currently in creation: Is there an unresolvable circular reference?
我减少了以下警告消息:@dependson(“testjobbean”)
我注意到job class中的自动服务正在导致它,但为什么呢?我该怎么做才能摆脱这些警告信息?
@Configuration
@ConditionalOnProperty(name = "quartz.enabled")
public class QuartzConfig {
@Autowired
private DataSource dataSource;
@Autowired
private PlatformTransactionManager transactionManager;
@Autowired
private ApplicationContext applicationContext;
@Autowired
List<Trigger> triggers;
@Bean
public JobFactory jobFactory() {
AutowiringSpringBeanJobFactory jobFactory = new AutowiringSpringBeanJobFactory();
jobFactory.setApplicationContext(applicationContext);
return jobFactory;
}
@Bean
public SchedulerFactoryBean schedulerFactoryBean(JobFactory jobFactory) throws IOException {
SchedulerFactoryBean factory = new SchedulerFactoryBean();
factory.setOverwriteExistingJobs(true);
factory.setDataSource(dataSource);
factory.setTransactionManager(transactionManager);
factory.setJobFactory(jobFactory);
factory.setQuartzProperties(quartzProperties());
if (triggers != null && !triggers.isEmpty()) {
factory.setTriggers(((Trigger[]) triggers.toArray(new Trigger[triggers.size()])));
}
return factory;
}
@Bean
public Properties quartzProperties() throws IOException {
PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
propertiesFactoryBean.afterPropertiesSet();
return propertiesFactoryBean.getObject();
}
public static SimpleTriggerFactoryBean createTrigger(JobDetail jobDetail, long pollFrequencyMs) {
SimpleTriggerFactoryBean factoryBean = new SimpleTriggerFactoryBean();
factoryBean.setJobDetail(jobDetail);
factoryBean.setRepeatInterval(pollFrequencyMs);
factoryBean.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT);
return factoryBean;
}
public static CronTriggerFactoryBean createCronTrigger(JobDetail jobDetail, String cronExpression) {
CronTriggerFactoryBean factoryBean = new CronTriggerFactoryBean();
factoryBean.setJobDetail(jobDetail);
factoryBean.setCronExpression(cronExpression);
factoryBean.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW);
return factoryBean;
}
public static JobDetailFactoryBean createJobDetail(Class<?> jobClass) {
JobDetailFactoryBean factoryBean = new JobDetailFactoryBean();
factoryBean.setJobClass(jobClass);
factoryBean.setDurability(true);
return factoryBean;
}
}
public final class AutowiringSpringBeanJobFactory extends SpringBeanJobFactory implements ApplicationContextAware {
private transient AutowireCapableBeanFactory beanFactory;
@Override
public void setApplicationContext(final ApplicationContext context) {
beanFactory = context.getAutowireCapableBeanFactory();
}
@Override
protected Object createJobInstance(final TriggerFiredBundle bundle) throws Exception {
final Object job = super.createJobInstance(bundle);
beanFactory.autowireBean(job);
return job;
}
}
@Component
@DisallowConcurrentExecution
public class TestJob implements Job {
@Autowired
private TestService service;
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
service.execute();
}
@Bean(name = "testJobBean")
public JobDetailFactoryBean createJobDetail() {
return QuartzConfig.createJobDetail(this.getClass());
}
@DependsOn("testJobBean")
@Bean(name = "testJobBeanTrigger")
public CronTriggerFactoryBean createTrigger(@Qualifier("testJobBean") JobDetail jobDetail,
@Value("${quartz.job.test.cronExpression}") String cronExpression) {
return QuartzConfig.createCronTrigger(jobDetail, cronExpression);
}
}
MyService.java
@Service
@Slf4j
public class MyService {
private TestRepository testRepository;
@Autowired
public MyService(TestRepository testRepository) {
this.testRepository = testRepository;
}
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void execute() {
log.debug("Job has been started");
List<TestObject> list = testRepository.findAll();
if (list != null && !list.isEmpty()) {
System.out.println("\n");
list.forEach(obj -> {
System.out.println(
"TestObject ID: " + obj.getId() + "\n" +
"SubTestObjects IDs: " + (obj.getSubTestObjects() == null ? "null" : obj.getSubTestObjects().toString()) +
"AnotherSubTestObjects IDs: " + (obj.getAnotherSubTestObjects() == null ? "null" : obj.getAnotherSubTestObjects().toString())
);
});
System.out.println();
log.info(list.size() + " test objects found");
} else {
log.info("No test objects were found");
}
log.debug("Job has been finished");
}
}
石英.属性
#============================================================================
# Configure Main Scheduler Properties
#============================================================================
org.quartz.scheduler.instanceId = AUTO
org.quartz.scheduler.makeSchedulerThreadDaemon = true
#============================================================================
# Configure ThreadPool
#============================================================================
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 1
org.quartz.threadPool.makeThreadsDaemons = true
#============================================================================
# Configure JobStore
#============================================================================
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
org.quartz.jobStore.useProperties = true
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.isClustered = true
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.clusterCheckinInterval 3600000
看来问题可能出在createjobdetail
方法中,请考虑以下代码段:
@Bean(name = "testJobBean")
public JobDetailFactoryBean createJobDetail() {
return QuartzConfig.createJobDetail(this.getClass());
}
@DependsOn("testJobBean")
@Bean(name = "testJobBeanTrigger")
public CronTriggerFactoryBean createTrigger(@Qualifier("testJobBean") JobDetail jobDetail,
@Value("${quartz.job.test.cronExpression}") String cronExpression) {
return QuartzConfig.createCronTrigger(jobDetail, cronExpression);
}
它在它的实现中使用this
来保存对当前对象的引用。但是,当前对象当时也可能在创建中,从而导致此错误。我将重新注释将这2个文件移到config
类。
此外,使用@dependson
也不是一个好的做法。
当打开同时使用这两个bean的页面时,我会看到异常: 请告知如何修复此异常。 编辑:我尝试使用setter注入,正如答案中所引用的那样
原因:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为“Hibernate Configuration”的bean时出错:通过字段“ReadDataSource01”表示的不满足依赖项;嵌套异常为org.springframework.beans.factory.BeanCreationException:创
我已经在我的Spring Boot应用程序中实现了一个调度程序例程,使用Quartz Scheduler遵循本教程(sping-boo-quitz-demo),并为我的目的做了一些修改。 例如,我的作业服务必须能够列出数据库中的所有对象及其子对象,设置新值并最终更新。所有这些都必须是事务性的。 出于某种原因,MyWork类不允许在其中声明事务性方法,所以我通过注入一个带有事务性方法的新服务类来解决
一切都开始了,因为Spring Cloud AWS没有正确配置SimpleStorage原型解决方案。此类负责在使用ResourceLoader时处理s3://协议。有关更多详细信息,请参阅问题:无法在Spring AWS示例上强制转换为org.springframework.core.io.WritableResource。 所以,我不得不手动创建它。但我也在使用LocalStack解决方案(h
我有一个批处理配置。我看到批处理过程默认使用。相反,我需要使用MySQL按批处理发送所有执行细节。但是当我使用以下代码时,我收到以下错误, 创建名称为“batchDataSource”的 Bean 时出错:请求的 Bean 当前正在创建中:是否存在无法解析的循环引用? 在我正在使用属性文件中, 我错过了什么?我正在使用JPA。甚至为什么它不使用可用的JPA数据源?如何在MemoryMap中强制Sp
我正在从事SpringBoot与Spring集成项目。升级应用程序时,我遇到以下错误(仅在pivotal cloud上,而不是本地)- 上下文初始化期间遇到异常-取消刷新尝试:org。springframework。豆。工厂未满足的依赖项异常:创建名为“cloudDataBaseConfiguration”的bean时出错:通过字段“cloud”表示未满足的依赖项:创建名为“cloudMultiH