没有DataSource的Spring启动+弹簧批处理 [英] Spring boot + spring batch without DataSource
问题描述
我正在尝试在spring boot项目中配置spring批处理,我想在没有数据源的情况下使用它。我发现 ResourcelessTransactionManager
是要走的路,但我不能让它工作。问题是我已经定义了另外3个dataSources,但是我不想在springBatch中使用它们。
I'm trying to configure spring batch inside spring boot project and I want to use it without data source. I've found that ResourcelessTransactionManager
is the way to go but I cannot make it work. Problem is I already have 3 another dataSources defined, but I don't want to use any of them in springBatch.
我检查了默认实现 DefaultBatchConfigurer
如果它无法找到dataSource,它将完全按照我的意愿行事。问题是我有3个并且不想使用任何。
I've checked default implementation DefaultBatchConfigurer
and if it is not able to find dataSource it will do exactly what I want. Problem is I've 3 of them and dont want to use any.
请不要建议在内存DB中使用hsql或其他因为我不想要它。
Please dont suggest to use hsql or other in memory DB as I dont want that.
推荐答案
我通过扩展DefaultBatchConfigurer类来解决这个问题,以便它忽略任何DataSource,因此它将配置一个基于地图的JobRepository 。
I got around this problem by extending the DefaultBatchConfigurer class so that it ignores any DataSource, as a consequence it will configure a map-based JobRepository.
示例:
@Configuration
@EnableBatchProcessing
public class BatchConfig extends DefaultBatchConfigurer {
@Override
public void setDataSource(DataSource dataSource) {
//This BatchConfigurer ignores any DataSource
}
}
这篇关于没有DataSource的Spring启动+弹簧批处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!