Search code examples
sap-commerce-cloudbackoffice

No bean named 'myJobPerformable' available


I'm trying to execute a cronjob from backoffice wizard handler.

  • CronJob item is defined in mybackoffice-items.xml, myCronJob
  • Job performable bean is defined in mybackoffice-backoffice-spring.xml, myJobPerformable
  • Wizard handler bean is defined in mybackoffice-backoffice-spring.xml, myHandler

myHandler calls executeJob() from its perform():

  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;
  }

The problem is happening when this code runs, it throws No bean named 'myJobPerformable' available.
However, the bean is already registered in mybackoffice-backoffice-spring.xml


Solution

  • Seems like moving your bean definition from mybackoffice-backoffice-spring.xml to mybackoffice-spring.xml should fix it as your bean then will be registered into the application context and will be available to service layer.

    Hope it helps!