异常

[2021-11-08 17:03:57] [ERROR] ErrorLogger: An error occured instantiating job to be executed. job= 'DEFAULT.helloJob'
org.quartz.SchedulerException: Problem instantiating class 'HelloJob' [See nested exception: java.lang.IllegalAccessException: Class org.quartz.simpl.SimpleJobFactory can not access a member of class HelloJob with modifiers ""]at org.quartz.simpl.SimpleJobFactory.newJob(SimpleJobFactory.java:58)at org.quartz.simpl.PropertySettingJobFactory.newJob(PropertySettingJobFactory.java:69)at org.quartz.core.JobRunShell.initialize(JobRunShell.java:127)at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:392)
Caused by: java.lang.IllegalAccessException: Class org.quartz.simpl.SimpleJobFactory can not access a member of class HelloJob with modifiers ""at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)at java.lang.Class.newInstance(Class.java:436)at org.quartz.simpl.SimpleJobFactory.newJob(SimpleJobFactory.java:56)... 3 more
[2021-11-08 17:03:57] [INFO] RAMJobStore: All triggers of Job DEFAULT.helloJob set to ERROR state.

错误代码

public class Test05 {public static void main(String[] args) throws SchedulerException {// 创建一个JobDetail实例,并且与HelloJob任务绑定JobDetail jobDetail = JobBuilder.newJob(HelloJob.class).withIdentity("helloJob").build();// 创建一个Trigger触发器实例,并且定义该job立即执行,并且每2秒执行一次,一直执行SimpleTrigger trigger = TriggerBuilder.newTrigger().withIdentity("helloTrigger").startNow().withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(2).repeatForever()).build();// 创建Schedule实例StdSchedulerFactory factory = new StdSchedulerFactory();Scheduler scheduler = factory.getScheduler();scheduler.start();scheduler.scheduleJob(jobDetail, trigger);}
}/*** 创建任务*/
class HelloJob implements Job {@Overridepublic void execute(JobExecutionContext jobExecutionContext) {// 打印当前的时间System.out.println("当前的时间是:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));// 具体在定时任务中要执行的操作,比如打印一段话System.out.println("Hello Quartz.");}
}

原因

其实提示信息Class SimpleJobFactory can not access a member of class HelloJob with modifiers ""说得很明白了,即HelloJob类的修饰符不正确。

由于需要写两个类,出于方便的考虑,把两个类放在一个java文件中,而一个java文件中只允许有一个public修饰符修饰的类,所以我就去掉了HelloJob类的public修饰符。

解决

将两个类分别写到两个java文件中,都使用public修饰符来修饰类。

正确代码

Test05.java

/*** 执行任务(或叫触发任务)*/
public class Test05 {public static void main(String[] args) throws SchedulerException {// 创建一个JobDetail实例,并且与HelloJob任务绑定JobDetail jobDetail = JobBuilder.newJob(HelloJob.class).withIdentity("helloJob").build();// 创建一个Trigger触发器实例,并且定义该job立即执行,并且每2秒执行一次,一直执行SimpleTrigger trigger = TriggerBuilder.newTrigger().withIdentity("helloTrigger").startNow().withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(2).repeatForever()).build();// 创建Schedule实例StdSchedulerFactory factory = new StdSchedulerFactory();Scheduler scheduler = factory.getScheduler();scheduler.start();scheduler.scheduleJob(jobDetail, trigger);}
}

HelloJob.java

/*** 创建任务*/
public class HelloJob implements Job {@Overridepublic void execute(JobExecutionContext jobExecutionContext) {// 打印当前的时间System.out.println("当前的时间是:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));// 具体在定时任务中要执行的操作,比如打印一段话System.out.println("Hello Quartz.");}
}

使用Quartz报错“Class SimpleJobFactory can not access a member of class HelloJob with modifiers “““相关推荐

  1. lua脚本在redis集群中执行报错--Lua script attempted to access a non local key in a cluster node...

    EVAL.EVALSHA命令 Redis从2.6.0版本开始提供了eval命令,通过内置的Lua解释器,可以让用户执行一段Lua脚本并返回数据.因为Redis单线程模型的特点,可以保证多个命令的原子性 ...

  2. 【git clone 报错】fatal: unable to access ‘https://github.com/zimeng303/React.git/‘: Failed to connect

    [git clone 报错]fatal: unable to access 'https://github.com/zimeng303/React.git/': Failed to connect t ...

  3. 宝塔面板不能备份数据库,数据库备份大小20K,数据库备份报错mysqldump: Got error: 1045: Access denied for user 'root'@'localhost'

    宝塔面板不能备份数据库 数据库备份大小20K 备份数据库报错 mysqldump: Got error: 1045: Access denied for user 'root'@'localhost' ...

  4. MySQL备份报错mysqldump: Got error: 1045: Access denied for user ‘root‘@‘localhost‘ (using password: YES)

    MySQL备份报错mysqldump: Got error: 1045: Access denied for user 'root'@'localhost' (using password: YES) ...

  5. git clone 报错:fatal: unable to access ‘https://github.com/xxxxxxxxx/xxx.git/‘: gnutls_

    完整报错:fatal: unable to access 'https://github.com/xxxxxxx/xxxx.git/': gnutls_handshake() failed: The ...

  6. git push报错:fatal: unable to access ‘https://XXXX.git/‘: Peer‘s Certificate issuer is not recognized.

    推镜像的时候,git push报错:fatal: unable to access 'https://XXXX.git/': Peer's Certificate issuer is not reco ...

  7. git push 报错:fatal: unable to access ‘https://github.com/...‘......

    问题: 在用git push 提交代码到 github 的时候,遇到了如下报错: fatal: unable to access 'https://github.com/-/': OpenSSL SS ...

  8. 解决git下载报错:fatal: unable to access ‘https://github.com/.../.git/‘:

    解决git下载报错:fatal: unable to access 'https://github.com/-/.git/':- 1.在git中执行git config --global --unse ...

  9. quartz 报错:java.lang.classNotFoundException

    最近在做一个调度平台改造的项目,quartz在测试环境跑的是单机环境,生产上两台服务器做集群. 测试环境是ok的,生产上线后报错,一个类java.lang.classNotFoundException ...

最新文章

  1. QT cannot open output file debug\OpencvTest.exe: Permission denied
  2. wdpc搭建https网站
  3. mysql 命令 例子_一个例子运用了所用mysql数据库操作命令
  4. 设计模式(一)简单工厂(创建型)(JavaPHP)
  5. JAVA常见异常种类
  6. PAT (Advanced Level) 1010 Radix(二分+模拟)
  7. vim查找关键字_VIM学习笔记 对话框(Dialog)
  8. 超干货议程发布 | 2021全球分布式云大会 · 上海站 重磅来袭
  9. ubuntu meld比较文件差异
  10. 平面设计素材|现代色彩风格的海报设计
  11. AnnotationTransactionAttributeSource is only available on Java 1.5 and higher
  12. 美国“加强软件供应链安全实践的指南” (SSDF V1.1草案) 解读来了
  13. 产品开发版本的延续性
  14. c++函数可变参数的使用
  15. 路由器的软件测试,路由器测试方法 - 软件测试网 _领测软件测试网站-中国软件测试技术第一门户...
  16. java rxtx下载_rxtx-2.1-7r2 jav
  17. kali攻击139端口_简易入侵139端口
  18. 阿狸心形表白html,qq分组心形图案一颗心
  19. 数据结构各结构特点(数组、链表、栈、队列、树)
  20. “钱多多”软件用户调查问卷的调查报告

热门文章

  1. Linux一键安装jdk (jdk-8u212-linux-x64.tar.gz 免费下载)
  2. 微软CEO鲍尔默最新致雅虎董事会信件翻译全文
  3. 硬盘序列号 c语言,怎么用标准的C语言读取硬盘的序列号
  4. 086-vdbench
  5. 德勤 Intern - online assessment prep(二)
  6. 【读书笔记】ZipArchive 类整理
  7. 2023年3月软考高项(信息系统项目管理师)报名走起!!!
  8. matlab有数据库吗,Matlab数据库的基本知识
  9. adams2015怎么把工具栏打开_照片上的文字怎么去除,三招教你搞定它!
  10. VIJOS 1321 魔塔