嗨还在学习希望有人可以填补空白
我有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(.....)(
.....
}
}
和
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(....){
.....
}
}
在我的应用程序上下文xml文件中,有以下行应允许我的作业启动程序查看并实例化上述服务。我认为&#34; base-package =&#34;指定要查找可以注入的@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>
有关为什么批处理系统无法注入依赖项的任何想法?
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(...)
}
}
答案 0 :(得分:1)
好吧,我不觉得傻。 问题是,在我假设我可以/将注入依赖性的时候。应用程序上下文是私有的。一旦我使应用程序上下文受到保护并获得服务。都工作了