我正在尝试从后台向导处理程序执行 cronjob。
- CronJob 项目在 mybackoffice-items.xml 中定义,myCronJob
- 作业可执行 bean 定义在 mybackoffice-backoffice-spring.xml、myJobPerformable
- 向导处理程序 bean 在 mybackoffice-backoffice-spring.xml、myHandler中定义
myHandler 从其 perform() 调用 executeJob():
private void executeJob() {
String springId = "myJobPerformable";
String id = springId;
JobModel myJob = getJob(springId).orElseGet(createJob(id, springId));
id = String.valueOf(this.keyGenerator.generate());
CronJobModel myCronJob = createCronJob(id, myJob);
this.cronJobService.performCronJob(myCronJob);
}
private Optional<JobModel> getJob(String springId) {
ServicelayerJobModel myJob = new ServicelayerJobModel();
myJob.setSpringId(springId);
try {
return Optional.ofNullable(flexibleSearchService.getModelByExample(myJob));
} catch (ModelNotFoundException e) {
return Optional.empty();
}
}
private Supplier<JobModel> createJob(String id, String springId) {
return () -> {
ServicelayerJobModel myJob = modelService.create(ServicelayerJobModel.class);
myJob.setCode(id);
myJob.setSpringId(springId);
modelService.save(myJob);
return myJob;
};
}
private MyCronJobModel createCronJob(String id, JobModel myJob) {
MyCronJobModel myCronJob = this.modelService.create(MyCronJobModel.class);
myCronJob.setCode(id);
myCronJob.setActive(Boolean.TRUE);
myCronJob.setJob(myJob);
myCronJob.setSessionUser(this.userService.getCurrentUser());
myCronJob.setSessionLanguage(this.commonI18NService.getCurrentLanguage());
myCronJob.setSessionCurrency(this.commonI18NService.getCurrentCurrency());
this.modelService.save(myCronJob);
return myCronJob;
}
运行此代码时会出现问题,它会抛出No bean named 'myJobPerformable' available。
但是,该 bean 已经在 mybackoffice-backoffice-spring.xml 中注册