问题
We are converting xml-based spring batch configuration to java config.
In xml form of JdbcCursorItemReader we were using late binding:
SELECT * FROM MY_TABLE_#{jobParameters[param1]}
How can this be implemented using Java config syntax?
回答1:
You can achieve this as follows:
@Bean
@StepScope
public JdbcCursorItemReader jdbcCursorItemReader(@Value("#{jobParameters['param1']}") String param1) {
return new JdbcCursorItemReaderBuilder<>()
.sql("SELECT * FROM MY_TABLE_" + param1)
// set other properties
.build();
}
The reference documentation contains a toggle on each page that allows you to see examples in either Java and Xml configuration. This can be helpful in your migration. See example here: https://docs.spring.io/spring-batch/4.0.x/reference/html/readersAndWriters.html#readersAndWriters
来源:https://stackoverflow.com/questions/51385720/spring-batch-late-binding-within-sql-using-java-config