Spring Batch Late Binding Within SQL Using Java Config

时光怂恿深爱的人放手 提交于 2019-12-25 00:12:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!