@Test public void test() { final ApplicationContextFactory factory = mock(ApplicationContextFactory.class); final Iterable<ApplicationContextFactory> factories = Arrays.asList(factory); final AutomaticJobRegistrar jobRegistrar = mock(AutomaticJobRegistrar.class); final ServiceJobFactoryRegistrar registrar = new ServiceJobFactoryRegistrar(jobRegistrar) { @Override protected Iterable<ApplicationContextFactory> lookupServices() { return factories; } }; registrar.registerJobFactories(); verify(jobRegistrar).addApplicationContextFactory(factory); }
protected void registerJobsFromJavaConfig(AutomaticJobRegistrar automaticJobRegistrar) throws ClassNotFoundException, IOException { List<Class<?>> classes = findMyTypes(getDefaultPackageToScanForBatchJobs()); for (Class<?> clazz : classes) { LOGGER.info("Register jobs from {}", clazz); automaticJobRegistrar.addApplicationContextFactory(new GenericApplicationContextFactory(clazz)); } }
@Bean public AutomaticJobRegistrar jobRegistrar(JobRegistry jobRegistry) throws Exception { AutomaticJobRegistrar registrar = new AutomaticJobRegistrar(); registrar.setJobLoader(new DefaultJobLoader(jobRegistry)); for (ApplicationContextFactory factory : applicationContext.getBeansOfType(ApplicationContextFactory.class).values()) { registrar.addApplicationContextFactory(factory); } return registrar; }
protected void registerJobsFromXml(AutomaticJobRegistrar automaticJobRegistrar) throws IOException { // Add all XML-Configurations to the AutomaticJobRegistrar ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver(); Resource[] xmlConfigurations = resourcePatternResolver.getResources("classpath*:" + env.getProperty("batch.config.path.xml", "/META-INF/spring/batch/jobs") + "/*.xml"); for (Resource resource : xmlConfigurations) { LOGGER.info("Register jobs from {}", resource); automaticJobRegistrar.addApplicationContextFactory(new GenericApplicationContextFactory(resource)); } }
protected void registerJobsFromJavaConfig(AutomaticJobRegistrar automaticJobRegistrar) throws ClassNotFoundException, IOException { List<Class<?>> classes = findMyTypes(env.getProperty("batch.config.package.javaconfig", "spring.batch.jobs")); for (Class<?> clazz : classes) { LOGGER.info("Register jobs from {}", clazz); automaticJobRegistrar.addApplicationContextFactory(new GenericApplicationContextFactory(clazz)); } }
@Override protected void addApplicationContextFactories(AutomaticJobRegistrar automaticJobRegistrar) throws Exception { registerJobsFromJavaConfig(automaticJobRegistrar); }
public ServiceJobFactoryRegistrar(final AutomaticJobRegistrar jobRegistrar) { this.jobRegistrar = jobRegistrar; }
/** * @see de.codecentric.batch.configuration.AutomaticJobRegistrarConfigurationSupport#addApplicationContextFactories(org.springframework.batch.core.configuration.support.AutomaticJobRegistrar) */ @Override protected void addApplicationContextFactories(AutomaticJobRegistrar automaticJobRegistrar) throws Exception { registerJobsFromXml(automaticJobRegistrar); registerJobsFromJavaConfig(automaticJobRegistrar); }
/** * Add ApplicationContextFactories to the given job registrar. * * @param automaticJobRegistrar Bean * @throws Exception Some error. */ protected abstract void addApplicationContextFactories(AutomaticJobRegistrar automaticJobRegistrar) throws Exception;
/** * Add ApplicationContextFactories to the given job registrar. * * @param automaticJobRegistrar * Bean * @throws Exception * Some error. */ protected abstract void addApplicationContextFactories(AutomaticJobRegistrar automaticJobRegistrar) throws Exception;