Java Spring Batch using embedded database for metadata and a second database for other data

后端 未结 1 457
自闭症患者
自闭症患者 2021-01-14 05:19

I\'m having a bit of trouble with Spring Batch. I am in this situation: I have to analyze the data inside a file and insert everything in a database (Oracle). The problem I

相关标签:
1条回答
  • 2021-01-14 05:45

    This is how I've solved it in the past. This was non-boot and old Spring, but it might still work with whatever environment you're in. By default the setDataSource() will be injected with your Oracle ds, but if you prevent it from being injected, Spring Batch will just store those details in memory.

    If you want a different datasource to be used (i.e. if you want the batch metadata to still be persisted), you could probably use @Qualifier to specify a different datasource bean and call super.setDataSource(dataSource);. Probably other ways to do it too, haven't touched this code in a few years.

    @Configuration
    @EnableBatchProcessing
    public class BatchConfig extends DefaultBatchConfigurer {
    
        @Override
        @Autowired
        public void setDataSource(DataSource dataSource) {
            // If we don't provide a datasource, an in-memory map will be used.
        }
    }
    
    0 讨论(0)
提交回复
热议问题