Spring launcher cannot access services

Hi still hope someone can fill in the blanks

I have a JSVC quartz spring system that has been running for over a year now. The launch of the task must be connected to 2 spring services that are successfully running in other parts of the system. Each service has several sql repositories or services into which it is entered. Please pay attention to package announcements. to record the context of the application.

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(.....)( ..... } } 

and

 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(....){ ..... } } 

There is the following line in my xml application context file, which should allow my launch manager to see and instantiate the above services. I think "base-package =" indicates packages to search for @services, @components and @repositories that can be entered.

  <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> 
  • I think that @Component should allow this class to see the services and install them and any dependencies (other services) that they have.
  • For some reason, the jsvc system only wants to call the class below with the NO arg constructor. and he does not introduce 2 services.
  • My unit tests can test a method using this service only if I provide a 2 argument constructor for MOCK services. Lll

Any thoughts on why a batch system cannot inject dependencies?

 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(...) } } 
+5
source share
1 answer

Well, I don't feel stupid. The problem was that at the moment when I assumed that I could / could introduce dependencies. The application context was closed. Once I have made my application context secure and receive services. everything worked

+1
source

Source: https://habr.com/ru/post/1246714/


All Articles