java - Same batch job with different property files depending on launch -
java - Same batch job with different property files depending on launch -
i have job definition in xml:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:batch="http://www.springframework.org/schema/batch" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.2.xsd"> <import resource="../config/config.xml"/> <import resource="../config/common.xml"/> <context:property-placeholder order="0" location="classpath:spring/batch/properties/processaccountingmessages.properties"/> <!-- batch job --> <batch:job id="processeventmessages" parent="abstractjob"> <batch:step id="processeventmessagesstep" parent="abstractstep"> <batch:tasklet transaction-manager="transactionmanager"> <batch:chunk reader="processeventmessagesreader" processor="processeventmessagesprocessor" writer="processeventmessageswriter" commit-interval="1" skip-limit="10"> <batch:skippable-exception-classes> <batch:include class="com.ing.crs.frwk.exp.crs2functionalexception" /> </batch:skippable-exception-classes> </batch:chunk> </batch:tasklet> </batch:step> </batch:job> <!-- beans --> <!-- tasklets --> <!-- readers --> <bean id="processeventmessagesreader" class="org.springframework.batch.item.database.jpapagingitemreader" scope="step"> <property name="entitymanagerfactory" ref="entitymanagerfactory"/> <property name="querystring" value="select a.id temprawevententity a.integrationtrycounter > 0 , a.serviceid = '#{jobparameters['partition.key']}' , (a.typeerror null or a.typeerror = com.ing.crs.data.dbenum.eventintegrationerrorcode.waiting) order a.id"/> <property name="transacted" value="false"/> </bean> <!-- proccessors --> <bean id="processeventmessagesprocessor" class="com.ing.crs.batch.spring.processevents.processor.processeventprocessor" scope="step"> <property name="sourceapplicationclassname" value="#{jobparameters['source.application.name']}"/> </bean> <!-- writers --> <bean id="processeventmessageswriter" class="com.ing.crs.batch.spring.common.writer.dummywriter"/> <!-- listeners --> <!-- utils --> <bean id="entitymanagerfactory" class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean"> <property name="datasource" ref="datasource"/> </bean> </beans> i launch this:
// create application context based on provided configuration. final applicationcontext context = new classpathxmlapplicationcontext(config); // create job launcher. uses fixed job launcher name @ moment! final joblauncher joblauncher = (joblauncher) context.getbean(job_launcher_name); // create job. final job job = (job) context.getbean(jobname); joblauncher.run(job, jobparameters); but i'm in need of exact same job definition, difference want utilize different properties.
<context:property-placeholder order="0" location="classpath:spring/batch/properties/processaccountingmessages.properties"/> so how can without having create new xml same job changing line property placeholder? don't want utilize jobparameters this. ideas?
i'd recommend using bean profiles this. using profile each version of properties want utilize allow specify 1 utilize @ runtime. can read more bean profiles here: http://spring.io/blog/2011/02/11/spring-framework-3-1-m1-released/
java spring-batch
Comments
Post a Comment