Spring作业启动器无法访问服务

pet*_*oke 5 spring spring-batch

嗨还在学习希望有人可以填补空白

我有JSVC石英弹簧批处理系统已经运行了一年多.Job启动程序需要连接到在系统其他部分成功运行的2个spring服务.每个服务都有许多sql存储库或服务注入其中.请记下包裹声明.用于应用程序上下文条目.

package com.mycompany.business.services.impl;
....
@Service
public class BatchProcessService {
   private final DomainSepcificRepository1 rep1;
   ...
   private final DomainSepcificRepositoryN repN;

   @Inject
   public BatchProcessService(Final final DomainSepcificRepository1 rep1,..., final DomainSepcificRepositoryN repN) {
   // injected values assigned to instance variables.
   }
   public List <...> findByCriteria(.....)(
      .....
   }
}
Run Code Online (Sandbox Code Playgroud)

package com.mycompany.business.services.impl;
 ....
 @Service
 public class EmailNotificationServiceImpl implements EmailNotificationService {

     private UserService userService;

     private final MailMessage mailMessage;

     private final MailTransport mailTransport;

     @Inject
     public EmailNotificationServiceImpl(final UserService userService, final MailMessage mailMessage, final MailTransport mailTransport) {
        this.userService = userService;
        this.mailMessage = mailMessage;
        this.mailTransport = mailTransport;
     }
     .....
     public void notifySupportStaff(....){
          .....
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的应用程序上下文xml文件中,有以下行应该允许我的作业启动器查看和实例化上述服务.我认为"base-package ="指定要查找可以注入的@services,@ component和@repositories的包.

 <context:component-scan base-package="com.mycompany.common.batch, com.mycompany.batch, com.mycompany.business.services" >
    <context:exclude-filter type="assignable" expression="com.mycompany.common.batch.scheduler.service.MyCompanySchedulerService"/>
 </context:component-scan>  
Run Code Online (Sandbox Code Playgroud)
  1. 我认为@Component应该允许这个类看到服务并实现它们以及它们拥有的任何依赖性(其他服务).
  2. 由于某种原因,jsvc系统只想使用NO arg构造函数调用下面的类.它并没有注入2项服务.
  3. 只有当我为MOCK服务提供2参数构造函数时,我的单元测试才能使用服务测试方法.LLL

有关为什么批处理系统无法注入依赖关系的任何想法?

package com.mycompany.batch.scheduler;
 ....
 @Inject
 private BatchProcessService batchProcessService;
 @Inject
 private EmailNotificationService emailNotificationService;
 @Component
 public class MyCompanySchedulerJobLauncher extends SchedulerJobLauncher {

 public MyCompanySchedulerJobLauncher() {
    super();
}

// @Inject
public MyCompanySchedulerJobLauncher(final BatchProcessService batchProcessService, final EmailNotificationService emailNotificationService) {
    super();
    this.batchProcessService = batchProcessService;
    this.emailNotificationService = emailNotificationService;
}

@Override
public int processJob(final JobExecutionContext context) throws JobRestartException, JobExecutionAlreadyRunningException, ParseException {
......
    if(batchProcessSerive.findByCriteria(....).size() == 0) {
        emailNotificationService.notifySupport(...)
     }
}
Run Code Online (Sandbox Code Playgroud)

pet*_*oke 1

好吧,我不觉得自己很傻。问题是,在我假设我可以/愿意注入依赖项的时候。应用程序上下文是私有的。一旦我保护了我的应用程序上下文并获取服务。一切正常