Announcement Announcement Module
Collapse
No announcement yet.
Problem with JobRegistry and JobRegistryBeanPostProcessor Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with JobRegistry and JobRegistryBeanPostProcessor

    Hi,

    I'm using Spring Batch 2.2.0 with Java Configuration.
    I'm trying to register my jobs in a JobRegistry using JobRegistryBeanPostProcessor but it seems it's not registering any job.

    Here is my config:

    Batch Config:
    Code:
    @Configuration
    @EnableBatchProcessing()
    @Import({ImportJobConfig.class})
    @Profile("dev")
    public class DevInfrastructureConfig implements BatchConfigurer {
    
        @Bean
        public DataSource dataSource() throws Exception {
            Context context = new InitialContext();
            return (DataSource) context.lookup("java:/datasources/JobRepository");
        }
    
        public PlatformTransactionManager getTransactionManager() {
            JtaTransactionManager jtaTransactionManager = new JtaTransactionManager();
            jtaTransactionManager.setAllowCustomIsolationLevels(true);
            jtaTransactionManager.afterPropertiesSet();
    
            return jtaTransactionManager;
        }
    
        public JobLauncher getJobLauncher() throws Exception {
            SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
            jobLauncher.setJobRepository(getJobRepository());
            jobLauncher.afterPropertiesSet();
            return jobLauncher;
        }
    
        public JobRepository getJobRepository() throws Exception {
            JobRepositoryFactoryBean jobRepository = new JobRepositoryFactoryBean();
            jobRepository.setDataSource(dataSource());
            jobRepository.setTransactionManager(getTransactionManager());
            jobRepository.setDatabaseType("h2");
    
            jobRepository.afterPropertiesSet();
            return (JobRepository) jobRepository.getObject();
        }
    
        private JobExplorer getJobExplorer() throws Exception {
            JobExplorerFactoryBean jobExplorerFactoryBean = new JobExplorerFactoryBean();
            jobExplorerFactoryBean.setDataSource(dataSource());
    
            jobExplorerFactoryBean.afterPropertiesSet();
    
            return (JobExplorer) jobExplorerFactoryBean.getObject();
        }
    
        @Bean
        public JobOperator jobOperator() throws Exception {
            SimpleJobOperator jobOperator = new SimpleJobOperator();
    
            jobOperator.setJobRepository(getJobRepository());
            jobOperator.setJobRegistry(getJobRegistry());
            jobOperator.setJobLauncher(getJobLauncher());
            jobOperator.setJobExplorer(getJobExplorer());
    
            return jobOperator;
        }
    
        private JobRegistry getJobRegistry() {
            return new MapJobRegistry();
        }
    
    
        @Bean
        public JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor() throws Exception {
            JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor = new JobRegistryBeanPostProcessor();
            jobRegistryBeanPostProcessor.setJobRegistry(getJobRegistry());
            jobRegistryBeanPostProcessor.afterPropertiesSet();
            return jobRegistryBeanPostProcessor;
        }
    }
    In ImportJobConfig.class I've a job configured and it's running flawlessly, but when I try to get the job lists from the JobOperator it returns an empty list.

    Am I missing something to configure properly the JobRegistryBeanPostProcessor.

    Thanks in advance.

  • #2
    Ok, I found a solution. Just have to create a DefaultJobLoader:
    Code:
        @Bean
        public DefaultJobLoader defaultJobLoader(){
            return new DefaultJobLoader(getJobRegistry());
        }

    Comment

    Working...
    X