【发布时间】:2014-11-12 08:57:38
【问题描述】:
通常,ItemReader 具有资源名称作为属性,我们可以将文件对象传递给 ItemReader 的任何实现。
我正在使用 3 版本的 Spring Batch API。
更新 :::
<bean id="cvsFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
<!-- Read a csv file -->
<property name="resource" value="classpath:cvs/I_10000_3ColRem_input_File.csv" />
<property name="lineMapper">
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<!-- split it -->
<property name="lineTokenizer">
<bean
class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
<property name="names" value="customerId,year,month,numPurchases,sow,purchaseAmt,cm,mc,multiChannel,loyalty,productReturn,relationDur,cb" />
</bean>
</property>
<property name="fieldSetMapper">
<!-- return back to reader, rather than a mapped object. -->
<!-- map to an object -->
<bean
class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
<property name="prototypeBeanName" value="testCLV" />
<property name="customEditors">
<map>
<entry key="java.lang.Double">
<ref local="doubleEditor" />
</entry>
</map>
</property>
</bean>
</property>
</bean>
</property>
</bean>
我的 App.java 看起来像
ApplicationContext context =
new ClassPathXmlApplicationContext(springConfig);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("reportJob");
try {
long a, b;
a = System.currentTimeMillis();
JobExecution execution = jobLauncher.run(job, new JobParameters());
b = System.currentTimeMillis();
System.out.println("Exit Status : " + execution.getStatus());
System.out.println("jobLauncher.run "+(b-a)+"mil to execute. ("+((b-a)/1000)+" seconds)");
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done");
我的要求是关注::
通过 web-application 用户将上传一个文件,我从中提取 inputStream
假设我有一个 streamInput obj 作为“streamInput”,我如何将它注入 ItemReader 的资源并运行我的工作。
【问题讨论】:
-
我认为没有。为什么需要这个功能?
-
我的要求是处理一个由网络应用程序上传的文件,所以我会有一个文件对象。如果我将文件保存在服务器上,那么它可能会遇到内存问题。你有解决这个问题的办法吗?
-
我认为 spring-integration 可以解决问题(但我帮不了你,对不起)。使用“spring-integration”标记问题以获得更广泛的可见性
标签: spring-batch spring-integration