[Logo]
Forums Register Login
Spring Batch: Passing runtime parameters to query in ItemReader using Qeury XML file
Hi all ,

I have used late binding in passing query at run time and it is running fine using properties file .Below is implementaion I have used

<bean id="placeholderProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="path to your properties file, either classpath: ... or c:/... " />
</bean>

In properties file :

sql=\
SELECT \
ID, \
NAME \
FROM TEST \
ORDER BY ID
Or starting from Spring 3, you can use SpEL:
<util:properties id="myProperties" location="..." />
...
<beans:bean ...
<beans:property name="sql" value="${sql}"/>
</beans:bean>

Now my actual requirement is to do same operation using XML file.I have prepared xml file as below

Queries.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE queries
[
<!ELEMENT queries (nativeQuery)>
<!ELEMENT nativeQuery (queryName,query)>
<!ELEMENT queryName (#PCDATA)>
<!ELEMENT query (#PCDATA)>
]>
<queries>
<nativeQuery>
<queryName>transactionQuery</queryName>
<query>select TRN_SERIAL from transactions</query>
</nativeQuery>
</queries>

In batch job I have configured using this line

<import resource="Queries.xml" />
but I'm unable to bind query in required place
<bean name="payoutReader" id="payoutReader" class="org.springframework.batch.item.database.JdbcCursorItemReader">
<property name="dataSource" ref="dinero-dataSource" />
<property name="sql" value="transactionQuery" />
<property name="rowMapper">
<bean name="mapper" id="mapper" class="com......." />
</property>
</bean>

please guide me in resolving this

Thanks
D.S

This thread has been viewed 4079 times.

All times above are in ranch (not your local) time.
The current ranch time is
Oct 15, 2018 09:45:54.