我有我的 xml:launch-context.xml 包含:
<bean id="flatFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
<property name="resource" value="file:#{jobParameters['input.file.name']}" />
<property name="lineMapper" ref="lineMapper"/>
</bean>
我想将 arg[0] 保存为文件路径。这是正确的方法吗?我不确定
public static void main(String[] args) {
JobParameters param = new JobParametersBuilder().addString("input.file.name", args[0]).toJobParameters();
ApplicationContext context = new ClassPathXmlApplicationContext("launch-context.xml");
}
谢谢
最佳答案
您所要做的就是将filePath
指向args[0]
。您应该在 Config 类中放置一个 setter 方法:
public static void setFilePath(String path) {
this.filePath = path;
}
并添加到您的 main 方法中(假设您的其他类的名称是 Config
):
Config.setFilePath(args[0]);
关于java - Spring Batch - 将参数传递到作业参数生成器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38706522/