|
| 1 | +<?xml version="1.0" encoding="UTF-8"?> |
| 2 | +<beans xmlns="http://www.springframework.org/schema/beans" |
| 3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 4 | + xmlns:c="http://www.springframework.org/schema/c" |
| 5 | + xmlns:context="http://www.springframework.org/schema/context" |
| 6 | + xmlns:lang="http://www.springframework.org/schema/lang" |
| 7 | + xmlns:p="http://www.springframework.org/schema/p" |
| 8 | + xmlns:util="http://www.springframework.org/schema/util" |
| 9 | + xmlns:batch="http://www.springframework.org/schema/batch" |
| 10 | + |
| 11 | + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd |
| 12 | + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd |
| 13 | + http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-4.0.xsd |
| 14 | + http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd |
| 15 | + http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd |
| 16 | +"> |
| 17 | + |
| 18 | + <import resource="classpath:database.xml" /> |
| 19 | + |
| 20 | + <!-- stored job-meta in database --> |
| 21 | + <bean id="jobRepository" |
| 22 | + class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean"> |
| 23 | + <property name="dataSource" ref="dataSource" /> |
| 24 | + <property name="transactionManager" ref="transactionManager" /> |
| 25 | + <property name="databaseType" value="derby" /> |
| 26 | + </bean> |
| 27 | + |
| 28 | + <bean id="jobLauncher" |
| 29 | + class="org.springframework.batch.core.launch.support.SimpleJobLauncher"> |
| 30 | + <property name="jobRepository" ref="jobRepository" /> |
| 31 | + </bean> |
| 32 | + |
| 33 | + <bean id="report" class="pl.altkom.sping.batch.sample.model.Report" scope="prototype" /> |
| 34 | + <bean id="itemProcessor" class="pl.altkom.sping.batch.sample.processor.CustomItemProcessor" /> |
| 35 | + |
| 36 | + <batch:job id="helloWorldJob"> |
| 37 | + <batch:step id="step1"> |
| 38 | + <batch:tasklet> |
| 39 | + <batch:chunk reader="cvsFileItemReader" writer="xmlItemWriter" |
| 40 | + processor="itemProcessor" commit-interval="10"> |
| 41 | + </batch:chunk> |
| 42 | + </batch:tasklet> |
| 43 | + </batch:step> |
| 44 | + </batch:job> |
| 45 | + |
| 46 | + <bean id="cvsFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader"> |
| 47 | + |
| 48 | + <property name="resource" value="classpath:csv-source.csv" /> |
| 49 | + |
| 50 | + <property name="lineMapper"> |
| 51 | + <bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper"> |
| 52 | + <property name="lineTokenizer"> |
| 53 | + <bean |
| 54 | + class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer"> |
| 55 | + <property name="names" value="id,sales,qty,staffName,date" /> |
| 56 | + </bean> |
| 57 | + </property> |
| 58 | + <property name="fieldSetMapper"> |
| 59 | + <bean class="pl.altkom.sping.batch.sample.mapper.ReportFieldSetMapper" /> |
| 60 | + |
| 61 | + <!-- if no data type conversion, use BeanWrapperFieldSetMapper to map by name |
| 62 | + <bean |
| 63 | + class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper"> |
| 64 | + <property name="prototypeBeanName" value="report" /> |
| 65 | + </bean> |
| 66 | + --> |
| 67 | + </property> |
| 68 | + </bean> |
| 69 | + </property> |
| 70 | + |
| 71 | + </bean> |
| 72 | + |
| 73 | + <bean id="xmlItemWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter"> |
| 74 | + <property name="resource" value="file:xml/outputs/report.xml" /> |
| 75 | + <property name="marshaller" ref="reportMarshaller" /> |
| 76 | + <property name="rootTagName" value="report" /> |
| 77 | + </bean> |
| 78 | + |
| 79 | + <bean id="reportMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"> |
| 80 | + <property name="marshallerProperties"> |
| 81 | + <map> |
| 82 | + <entry key="jaxb.formatted.output"> |
| 83 | + <value type="boolean">true</value> |
| 84 | + </entry> |
| 85 | + </map> |
| 86 | + </property> |
| 87 | + <property name="classesToBeBound"> |
| 88 | + <list> |
| 89 | + <value>pl.altkom.sping.batch.sample.model.Report</value> |
| 90 | + </list> |
| 91 | + </property> |
| 92 | + |
| 93 | + </bean> |
| 94 | + |
| 95 | +</beans> |
0 commit comments