Java 同一批作业具有不同的属性文件,具体取决于启动
我在xml中有一个作业定义:Java 同一批作业具有不同的属性文件,具体取决于启动,java,spring-batch,Java,Spring Batch,我在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.springfra
<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 FROM TempRawEventEntity a where a.integrationTryCounter > 0 and a.serviceId = '#{jobParameters['partition.key']}' and (a.typeError IS null or a.typeError = com.ing.crs.data.dbenum.EventIntegrationErrorCode.WAITING) order by 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>
但现在我需要完全相同的工作定义,但唯一的区别是我想要使用不同的属性
<context:property-placeholder order="0"
location="classpath:spring/batch/properties/ProcessAccountingMessages.properties"/>
那么,我怎样才能轻松地做到这一点,而不必使用相同的作业创建一个新的xml,只需更改带有属性占位符的行?我也不想为此使用jobParameters。有什么想法吗?我建议使用bean配置文件来实现这一点。为要使用的属性的每个版本使用配置文件将允许您指定在运行时使用哪个版本。你可以在这里阅读更多关于bean配置文件的信息:好的,我一直在尝试它,它似乎是最好的解决方案。谢谢。
<context:property-placeholder order="0"
location="classpath:spring/batch/properties/ProcessAccountingMessages.properties"/>