簡體   English   中英

如何在xml中設置Spring Batch jobParameters?

[英]How do I set Spring Batch jobParameters in xml?

使用參數時,此job.xml效果很好。

<beans>
    <bean id="testFileItemWriter" class="org.springframework.batch.item.file.FlatFileItemWriter" scope="step">
        <property name="resource" value="#{jobParameters['paramFileOuput']}"/>
        <property name="shouldDeleteIfExists" value="true" />

        <property name="lineAggregator">
                    ...
        </property>
  </bean>
</beans>

但是,如果我不想使用作業參數而是使用Spring概要文件怎么辦...

<beans>
    <bean id="testFileItemWriter" class="org.springframework.batch.item.file.FlatFileItemWriter" scope="step">
        <property name="resource" ref="testFileOutput"/>
        <property name="shouldDeleteIfExists" value="true" />

        <property name="lineAggregator">
                    ....
        </property>
  </bean>
  <beans profile="dev">
       <bean id="testFileOutput" class="java.lang.String">
           <constructor-arg type="java.lang.String" value="file:c:/temp/testfile.txt" />
       </bean>
  </beans>
  <beans profile="prod">
       <bean id="testFileOutput" class="java.lang.String">
           <constructor-arg type="java.lang.String" value="file:pathtoprod.txt" />
       </bean>
  </beans>
</beans>

這似乎起作用。 但這感覺不對。 有沒有一種方法可以使用配置文件在xml中設置參數?

遵循這些原則(這顯然行不通)

<beans profile="dev">
    <setJobParameter key="testFileOuput" value="file:c:/temp/testfile.txt" />
</beans>

我可以使用任何版本的spring或springbatch。

這個怎么樣:

public FileOutput { 
private String filename; 
...
} 

<beans profile="dev">
      <bean id="testFileOutput" class="FileOutput " c:filename="file:pathtoprod.txt">
</beans>

不幸的是,您不能將p / c名稱空間與java.lang.String一起使用,這就是為什么您需要一些輔助類的原因。 無論如何,該解決方案會將您的context.xml縮小幾行,並且看起來與所需的解決方案更加相似。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM