侧边栏壁纸
博主头像
成云博主等级

行动起来,活在当下

  • 累计撰写 40 篇文章
  • 累计创建 25 个标签
  • 累计收到 2 条评论

目 录CONTENT

文章目录

spring-boot启动项目时候,出现错误 Field scheduler in com.jeesite.modules.quartz.service.QuartzJobService

佳航
2020-09-30 / 0 评论 / 0 点赞 / 1724 阅读 / 3320 字

今天整合jeesite4项目时,将jeecg里面的定时器功能拿出来集成到jeesite4中,启用服务器的时候出现了如下错误:

09-30 20:20:55.127 WARN  [o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myCommandLineRunner': Unsatisfied dependency expressed through field 'quartzJobService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'quartzJobService': Unsatisfied dependency expressed through field 'scheduler'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.quartz.Scheduler' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
09-30 20:20:55.150 INFO  [o.s.b.a.l.AutoConfigurationReportLoggingInitializer] - 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
09-30 20:20:55.275 ERROR [o.s.b.diagnostics.LoggingFailureAnalysisReporter] - 

***************************
APPLICATION FAILED TO START
***************************

Description:

Field scheduler in com.jeesite.modules.quartz.service.QuartzJobService required a bean of type 'org.quartz.Scheduler' that could not be found.


Action:

Consider defining a bean of type 'org.quartz.Scheduler' in your configuration.

========= Enabled refresh mybatis mapper =========

字面上就是service里面无法找到Scheduler,这个应该是在启动的时候未注入到容器中,
后来谷歌搜了一个方法,将获取Scheduler用方法注入进去,这样就解决问题啦,记录下问题。花了有点长的时间。

 
package com.jeesite.modules.quartz.service;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SampleSchedulerConfiguration {
    @Bean
    public Scheduler getScheduler() throws SchedulerException       
	 return StdSchedulerFactory.getDefaultScheduler();
  }

}

@Component 是类级别的注解 @Bean方法级别的注解 用他的方法名作为名字注入到容器中,以供其他service调用。写好后就可以正常启动了

0

评论区