spring boot spring batch: how to set query dynamically to ItemReader -


i new spring. have use case need execute same multiple sql queries , return same pojo every query. write 1 item reader , change query in each step. there way this?

you can use spring batch late binding adding @stepscope in reader

sample code

@stepscope @bean public itemreader<pojo> myreader() {     jdbccursoritemreader<pojo> reader = new jdbccursoritemreader<>();     reader.setdatasource(basicdatasource);     //you can inject sql per need      //some expamles      //using #{jobparameters['']}     //using {jobexecutioncontext['input.file.name']}"      //using #{stepexecutioncontext['input.file.name']}"     reader.setsql("your-sql");           reader.setrowmapper(new mymapper());     return reader; } 

check section 5.4 https://docs.spring.io/spring-batch/reference/html/configurestep.html


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -