{"record":{"id":"588af5d8ef62f441","repo":"elunez/eladmin","slug":"error-588af5","errorCode":null,"errorMessage":"创建定时任务失败","messagePattern":"创建定时任务失败","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/QuartzManage.java","lineNumber":72,"sourceCode":"            cronTrigger.getJobDataMap().put(QuartzJob.JOB_KEY, quartzJob);\n\n            //重置启动时间\n            ((CronTriggerImpl)cronTrigger).setStartTime(new Date());\n\n            //执行定时任务，如果是持久化的，这里会报错，捕获输出\n            try {\n                scheduler.scheduleJob(jobDetail,cronTrigger);\n            } catch (ObjectAlreadyExistsException e) {\n                log.warn(\"定时任务已存在，跳过加载\");\n            }\n\n            // 暂停任务\n            if (quartzJob.getIsPause()) {\n                pauseJob(quartzJob);\n            }\n        } catch (Exception e){\n            log.error(\"创建定时任务失败\", e);\n            throw new BadRequestException(\"创建定时任务失败\");\n        }\n    }\n\n    /**\n     * 更新job cron表达式\n     * @param quartzJob /\n     */\n    public void updateJobCron(QuartzJob quartzJob){\n        try {\n            TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId());\n            CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);\n            // 如果不存在则创建一个定时任务\n            if(trigger == null){\n                addJob(quartzJob);\n                trigger = (CronTrigger) scheduler.getTrigger(triggerKey);\n            }\n            CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(quartzJob.getCronExpression());\n            trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/QuartzManage.java#L54-L90","documentation":"QuartzManage.addJob wraps scheduler.scheduleJob(jobDetail, cronTrigger) in a blanket catch(Exception); only ObjectAlreadyExistsException is tolerated (job already present at startup restore). Any other scheduler failure — building the trigger, job registration, or the immediate pauseJob call — is logged and rethrown as BadRequestException '创建定时任务失败'. The underlying exception is in the server log; the API response intentionally hides it.","triggerScenarios":"Creating a job (create calls addJob after save) when the Scheduler is misconfigured or shut down, the JobDataMap references a bean missing from Spring context, or a ClassCastException/internal SchedulerException occurs. Since create() is @Transactional, the DB row is also rolled back.","commonSituations":"Quartz clustered mode with a broken QRTZ_ table schema or datasource; scheduler auto-startup disabled; the scheduled job class failing to instantiate; serializing non-serializable data into the JobDataMap.","solutions":["Read the full stack trace after the '创建定时任务失败' log line — it names the real exception; fix that root cause.","Verify the quartz tables/schema exist and match your Quartz version if using JDBC job store.","Ensure the job bean/class is resolvable in Spring context (see also error 26 validation) and its state is serializable.","Confirm the Scheduler bean is not in standby/shutdown state (check spring.quartz.auto-startup and any manual scheduler.shutdown() calls)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-flight: scheduler healthy and bean resolvable before create\nif (!scheduler.isStarted()) throw new IllegalStateException(\"Quartz scheduler not started\");\nif (!SpringBeanHolder.getAllServiceBeanName().contains(job.getBeanName())) throw new IllegalArgumentException(\"bean missing\");","typeGuard":null,"tryCatchPattern":"try { quartzJobService.create(job); } catch (BadRequestException e) { // real cause is in the server log after \"创建定时任务失败\" log.error(e.getMessage(), e); return fail(\"创建失败，请查看服务端日志定位根因\"); }","preventionTips":["Always pull the underlying stack trace from the log — the API message is deliberately generic.","Verify quartz table schema matches the Quartz version when using JDBC store.","Keep quartz_job rows and scheduler state consistent; wipe both together."],"tags":["quartz","scheduler","transactions","diagnostics"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}