栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Spring Batch和Spring集成

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring Batch和Spring集成

绝对。您可以将JDBC

ItemReader
或JPA
ItemReader
与一起使用,
ColumnMapRowMapper
以检索
Map
结果集。您可以使用它
FlatFileItemWriter
简单地以您喜欢的任何格式输出数据(使用提供的类很容易定界;固定宽度表示编写一个类以将转换
Map
为固定宽度字符串)。

我经常在Spring Batch中执行此操作,而这几乎只是布线的问题。

除了定义资源,数据源和提供SQL之外,这种(未经测试的)配置几乎可以完全满足您的要求:

<?xml version="1.0" encoding="UTF-8"?><beans:beans xmlns="http://www.springframework.org/schema/batch"    xmlns:beans="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"    xsi:schemaLocation="        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd        http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.0.xsd        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">    <job-repository id="jobRepository"        data-source="jobDataSource"/>    <beans:bean id="transactionManager"     p:dataSource-ref="jobDataSource" />    <beans:bean id="extractReader" scope="step"        >        <beans:property name="dataSource" ref="appDataSource" />        <beans:property name="rowMapper"> <beans:bean      />        </beans:property>        <beans:property name="sql"> <beans:value>     . . . </beans:value>        </beans:property>    </beans:bean>    <beans:bean id="extractWriter"         scope="step">        <beans:property name="resource" ref="fileResource" />        <beans:property name="lineAggregator"> <beans:bean     >     <beans:property name="delimiter">         <util:constant  static-field="org.springframework.batch.item.file.transform.DelimitedLineTokenizer.DELIMITER_TAB" />     </beans:property>     <beans:property name="fieldExtractor">         <beans:bean   />     </beans:property> </beans:bean>        </beans:property>    </beans:bean>    <job id="extractJob" restartable="true">        <step id="extractStep" > <tasklet>     <chunk reader="extractReader" writer="extractWriter"         commit-interval="100" /> </tasklet>        </step>    </job></beans:beans>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/454981.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号