spring 批处理中的嵌套查询
Nested Query in spring batch processing
我想使用 Spring Batch 创建一个 ETL 过程,这些步骤将从 DB 中读取并插入到一个 DB 中,所以基本上我是从不同的 DB 收集相似的信息并插入它们在一个数据库中,我有一个大型复杂查询,我需要在这些数据库上 运行 并且结果将插入所谓的一个数据库中以供以后处理,我的主要音乐会是我想在中引用此查询JpaPagingItemReader 例如,它有一种方法我可以在我的项目中将此查询添加为 .sql 文件,然后在 reader?
中引用它
或者我可以遵循的任何其他解决方案?
谢谢
it there a way I can for example add this query in my project as .sql file and then reference it in the reader? Or any other solution I can follow?
您可以将查询放在属性文件中并注入 reader,例如:
@Configuration
@EnableBatchProcessing
@PropertySource("classpath:application.properties")
public class MyJob {
@Bean
public JpaPagingItemReader itemReader(@Value("${query}") String query) {
return new JpaPagingItemReaderBuilder<>()
.queryString(query)
// set other reader properties
.build();
}
// ...
}
在此示例中,您应该在 application.properties
中有一个 属性 query=your sql query
。这实际上是常规的 Spring 属性 注入机制,这里没有 Spring 特定于批处理的内容。
我想使用 Spring Batch 创建一个 ETL 过程,这些步骤将从 DB 中读取并插入到一个 DB 中,所以基本上我是从不同的 DB 收集相似的信息并插入它们在一个数据库中,我有一个大型复杂查询,我需要在这些数据库上 运行 并且结果将插入所谓的一个数据库中以供以后处理,我的主要音乐会是我想在中引用此查询JpaPagingItemReader 例如,它有一种方法我可以在我的项目中将此查询添加为 .sql 文件,然后在 reader?
中引用它或者我可以遵循的任何其他解决方案?
谢谢
it there a way I can for example add this query in my project as .sql file and then reference it in the reader? Or any other solution I can follow?
您可以将查询放在属性文件中并注入 reader,例如:
@Configuration
@EnableBatchProcessing
@PropertySource("classpath:application.properties")
public class MyJob {
@Bean
public JpaPagingItemReader itemReader(@Value("${query}") String query) {
return new JpaPagingItemReaderBuilder<>()
.queryString(query)
// set other reader properties
.build();
}
// ...
}
在此示例中,您应该在 application.properties
中有一个 属性 query=your sql query
。这实际上是常规的 Spring 属性 注入机制,这里没有 Spring 特定于批处理的内容。