开发者社区> 问答> 正文

Spring Boot 配置定时任务quartz报错[The job (DEFA?报错

我在spring boot里面配置了如下任务

@Bean(name = "schedulerFactoryBean")
	public SchedulerFactoryBean createSchedulerFactoryBean()throws Exception
	{
		SchedulerFactoryBean bean = new SchedulerFactoryBean();

		JobDetail job1 = newJob(SimpleJob.class).withIdentity("job1", "group1").storeDurably(true).build();
	
		CronTrigger trigger1 = newTrigger().withIdentity("trigger1", "group1").forJob("job1").withSchedule(cronSchedule("0/2 * * * * ?")).build();
	        
		bean.setJobDetails(job1);
		bean.setTriggers(trigger1);
		
		return bean;
	}



然而,启动报错了。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schedulerFactoryBean' defined in com.pp.App2: Invocation of init method failed; nested exception is org.quartz.JobPersistenceException: The job (DEFAULT.job1) referenced by the trigger does not exist.
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:753) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
	at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
	at com.pp.App2.main(App2.java:73) [classes/:na]
Caused by: org.quartz.JobPersistenceException: The job (DEFAULT.job1) referenced by the trigger does not exist.
	at org.quartz.simpl.RAMJobStore.storeTrigger(RAMJobStore.java:422) ~[quartz-2.2.2.jar:na]
	at org.quartz.core.QuartzScheduler.scheduleJob(QuartzScheduler.java:932) ~[quartz-2.2.2.jar:na]
	at org.quartz.impl.StdScheduler.scheduleJob(StdScheduler.java:258) ~[quartz-2.2.2.jar:na]
	at org.springframework.scheduling.quartz.SchedulerAccessor.addTriggerToScheduler(SchedulerAccessor.java:312) ~[spring-context-support-4.2.5.RELEASE.jar:4.2.5.RELEASE]
	at org.springframework.scheduling.quartz.SchedulerAccessor.registerJobsAndTriggers(SchedulerAccessor.java:235) ~[spring-context-support-4.2.5.RELEASE.jar:4.2.5.RELEASE]
	at org.springframework.scheduling.quartz.SchedulerFactoryBean.afterPropertiesSet(SchedulerFactoryBean.java:512) ~[spring-context-support-4.2.5.RELEASE.jar:4.2.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
	... 16 common frames omitted


spring boot使用的版本是:1.3.3.RELEASE

请问,这是什么错误。怎么回事

展开
收起
爱吃鱼的程序员 2020-06-09 15:53:55 3789 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
    Thejob(DEFAULT.job1)referencedbythetriggerdoesnotexist.怎么解决的,楼主? @西夏一品堂触发器没关联上什么意思,怎么解决 schedulerFactoryBean2 你有这个bean吗?是我帖代码的时候,弄错了。就是第一个里面配置的bean 看这个bean从哪冒出来的?这个bean注解去掉或者配置好 

    在启动类加上 @EnableScheduling 就可以很方便的使用 quartz了。



    我项目里面有很多计划任务要跑,我想要对指定(某个)的任务进行停止,启动这个springboot支持吗?
    2020-06-09 15:54:11
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载

相关实验场景

更多