没有名为“ myJobPerformable”的bean

时间:2019-11-25 19:02:54

标签: hybris backoffice

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

此代码运行时发生问题,它引发没有名为'myJobPerformable'的bean。
但是,该bean已经在mybackoffice-backoffice-spring.xml中注册了

1 个答案:

答案 0 :(得分:3)

好像您将bean定义从mybackoffice-backoffice-spring.xml移到mybackoffice-spring.xml一样,应该对其进行修复,因为您的bean随后将被注册到应用程序上下文中并且可用于服务层。

希望有帮助!