我如何添加属性:
<property name="myProperty" value="value"/>
批处理作业定义:
<batch:job id="MyJob">
<batch:description>description</batch:description>
<batch:step id="step0">
<batch:tasklet ref="MyJobCls"/>
<batch:listeners>
<batch:listener ref="MyJobkListener"/>
</batch:listeners>
</batch:step>
</batch:job>
然后我可以在我的运行时间使用此属性。
答案 0 :(得分:2)
您可以将属性放在外部文件中,或者从xml中将其注入PropertyPlaceholderConfigurer:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location"><value>my_config.properties</value></property>
<property name="properties">
<props>
<prop key="myProperty">value</prop>
</props>
</property>
</bean>
此处有更多详情:Using Properties in spring config
此外,如果您使用CommandLineJobRunner运行流程,您可以使用-D(How do I read JVM arguments in the Spring applicationContext.xml)从命令行设置它 a-DmyProperty =值
对于MyJobCls / MyJobkListener中的myProperty值,您可以选择:
注释How can I inject a property value into a Spring Bean which was configured using annotations?
或从xml配置注入: http://www.mkyong.com/spring/spring-propertyplaceholderconfigurer-example/
答案 1 :(得分:0)
我有点困惑,你在问什么样的财产。 字符串或弹簧托管bean的某种或引用。
如果需要一些字符串键值对,请在spring-batch-job参数中定义它。它将在整个工作中完成所有步骤/.
如果要为引用/类提供一些属性,则在自定义步骤或自定义作业类中将该属性/类作为成员变量添加为setter和getter。 您也可以对字符串属性执行相同的操作。