1

我正在尝试从后台向导处理程序执行 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 中注册

4

1 回答 1

3

似乎将您的bean定义从移动mybackoffice-backoffice-spring.xmlmybackoffice-spring.xml应该修复它,因为您的bean然后将被注册到应用程序上下文中并且将可用于服务层。

希望能帮助到你!

于 2019-11-26T03:06:46.390 回答