1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.springframework.batch.core.configuration.annotation;
17
18 import java.util.Collection;
19
20 import org.springframework.batch.core.configuration.support.ApplicationContextFactory;
21 import org.springframework.batch.core.configuration.support.AutomaticJobRegistrar;
22 import org.springframework.batch.core.configuration.support.DefaultJobLoader;
23 import org.springframework.batch.core.launch.JobLauncher;
24 import org.springframework.batch.core.repository.JobRepository;
25 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.context.ApplicationContext;
27 import org.springframework.context.annotation.Bean;
28 import org.springframework.context.annotation.Configuration;
29 import org.springframework.transaction.PlatformTransactionManager;
30
31
32
33
34
35
36
37
38
39 @Configuration
40 public class ModularBatchConfiguration extends AbstractBatchConfiguration {
41
42 @Autowired
43 private ApplicationContext context;
44
45 @Autowired(required = false)
46 private Collection<BatchConfigurer> configurers;
47
48 private AutomaticJobRegistrar registrar = new AutomaticJobRegistrar();
49
50 @Override
51 @Bean
52 public JobRepository jobRepository() throws Exception {
53 return getConfigurer(configurers).getJobRepository();
54 }
55
56 @Override
57 @Bean
58 public JobLauncher jobLauncher() throws Exception {
59 return getConfigurer(configurers).getJobLauncher();
60 }
61
62 @Override
63 @Bean
64 public PlatformTransactionManager transactionManager() throws Exception {
65 return getConfigurer(configurers).getTransactionManager();
66 }
67
68 @Bean
69 public AutomaticJobRegistrar jobRegistrar() throws Exception {
70 registrar.setJobLoader(new DefaultJobLoader(jobRegistry()));
71 for (ApplicationContextFactory factory : context.getBeansOfType(ApplicationContextFactory.class).values()) {
72 registrar.addApplicationContextFactory(factory);
73 }
74 return registrar;
75 }
76
77 }