Restructure samples by feature

This commit is contained in:
Mahmoud Ben Hassine
2023-10-09 15:45:27 +02:00
parent b1ac90df68
commit 474b3f4cf2
187 changed files with 1300 additions and 755 deletions

View File

@@ -0,0 +1,16 @@
## Reader Writer adapter Sample
### About
This sample shows the delegate pattern again, and also the
`ItemReaderAdapter` which is used to adapt a POJO to the
`ItemReader` interface.
## Run the sample
You can run the sample from the command line as following:
```
$>cd spring-batch-samples
$>../mvnw -Dtest=DelegatingJobFunctionalTests#testLaunchJob test
```

View File

@@ -0,0 +1,15 @@
## Tasklet Adapter Sample
### About
This sample shows the delegate pattern again, to adapt an
existing service to a `Tasklet`.
## Run the sample
You can run the sample from the command line as following:
```
$>cd spring-batch-samples
$>../mvnw -Dtest=TaskletAdapterJobFunctionalTests#testLaunchJob test
```

View File

@@ -0,0 +1,27 @@
/*
* Copyright 2006-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.adapter.tasklet;
import org.springframework.batch.core.scope.context.ChunkContext;
public class Task {
public boolean doWork(ChunkContext chunkContext) {
chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext().put("done", "yes");
return true;
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.sample.rabbitmq;
package org.springframework.batch.sample.amqp;
import javax.sql.DataSource;
@@ -29,7 +29,6 @@ import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.amqp.builder.AmqpItemReaderBuilder;
import org.springframework.batch.item.amqp.builder.AmqpItemWriterBuilder;
import org.springframework.batch.sample.rabbitmq.processor.MessageProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.rabbitmq.amqp;
package org.springframework.batch.sample.amqp;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
@@ -34,8 +34,8 @@ public final class AmqpMessageProducer {
private static final int SEND_MESSAGE_COUNT = 10;
private static final String[] BEAN_CONFIG = { "classpath:/META-INF/spring/jobs/messaging/rabbitmq-beans.xml",
"classpath:/META-INF/spring/config-beans.xml" };
private static final String[] BEAN_CONFIG = {
"classpath:org/springframework/batch/sample/amqp/job/rabbitmq-beans.xml" };
public static void main(String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(BEAN_CONFIG);

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.rabbitmq.processor;
package org.springframework.batch.sample.amqp;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.lang.Nullable;

View File

@@ -19,6 +19,6 @@ You can run the sample from the command line as following:
```
cd spring-batch-samples
# Launch the test using the XML configuration
../mvnw -Dtest=AMQPJobFunctionalTests#testLaunchJobWithXmlConfig test
../mvnw -Dtest=AmqpJobFunctionalTests#testLaunchJobWithXmlConfig test
# Launch the test using the Java configuration
../mvnw -Dtest=AMQPJobFunctionalTests#testLaunchJobWithJavaConfig test
../mvnw -Dtest=AmqpJobFunctionalTests#testLaunchJobWithJavaConfig test

View File

@@ -0,0 +1,28 @@
## BeanWrapperMapper Sample
### About
This sample shows the use of automatic mapping from fields in a file
to a domain object. The `Trade` and `Person` objects needed
by the job are created from the Spring configuration using prototype
beans, and then their properties are set using the
`BeanWrapperFieldSetMapper`, which sets properties of the
prototype according to the field names in the file.
Nested property paths are resolved in the same way as normal Spring
binding occurs, but with a little extra leeway in terms of spelling
and capitalisation. Thus for instance, the `Trade` object has a
property called `customer` (lower case), but the file has been
configured to have a column name `CUSTOMER` (upper case), and
the mapper will accept the values happily. Underscores instead of
camel-casing (e.g. `CREDIT_CARD` instead of `creditCard`)
also work.
### Run the sample
You can run the sample from the command line as following:
```
$>cd spring-batch-samples
$>../mvnw -Dtest=BeanWrapperMapperSampleJobFunctionalTests#testJobLaunch test
```

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.sample.remotechunking;
package org.springframework.batch.sample.chunking;
import javax.sql.DataSource;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.remotechunking;
package org.springframework.batch.sample.chunking;
import java.util.Arrays;
@@ -51,7 +51,7 @@ import org.springframework.integration.jms.dsl.Jms;
@EnableBatchProcessing
@EnableBatchIntegration
@EnableIntegration
@PropertySource("classpath:remote-chunking.properties")
@PropertySource("classpath:org/springframework/batch/sample/chunking/remote-chunking.properties")
@Import(DataSourceConfiguration.class)
public class ManagerConfiguration {

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.remotechunking;
package org.springframework.batch.sample.chunking;
import jakarta.jms.JMSException;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
@@ -50,7 +50,7 @@ import org.springframework.integration.jms.dsl.Jms;
@EnableBatchProcessing
@EnableBatchIntegration
@EnableIntegration
@PropertySource("classpath:remote-chunking.properties")
@PropertySource("classpath:org/springframework/batch/sample/chunking/remote-chunking.properties")
@Import(DataSourceConfiguration.class)
public class WorkerConfiguration {

View File

@@ -14,10 +14,11 @@
* limitations under the License.
*/
package org.springframework.batch.sample.jmx;
package org.springframework.batch.sample.common;
import org.aspectj.lang.JoinPoint;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.sample.misc.jmx.SimpleMessageApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;

View File

@@ -0,0 +1,24 @@
## Composite ItemWriter Sample
### About
This shows a common use case using a composite pattern, composing
instances of other framework readers or writers. It is also quite
common for business-specific readers or writers to wrap
off-the-shelf components in a similar way.
In this job the composite pattern is used just to make duplicate
copies of the output data. The delegates for the
`CompositeItemWriter` have to be separately registered as
streams in the `Step` where they are used, in order for the step
to be restartable. This is a common feature of all delegate
patterns.
### Run the sample
You can run the sample from the command line as following:
```
$>cd spring-batch-samples
$>../mvnw -Dtest=CompositeItemWriterSampleFunctionalTests#testJobLaunch test
```

View File

@@ -19,7 +19,7 @@ package org.springframework.batch.sample.domain.person;
import java.util.ArrayList;
import java.util.List;
import org.springframework.batch.sample.domain.order.Address;
import org.springframework.batch.sample.file.patternmatching.Address;
public class Person {

View File

@@ -19,7 +19,7 @@ package org.springframework.batch.sample.domain.person;
import java.util.ArrayList;
import java.util.List;
import org.springframework.batch.sample.domain.order.Address;
import org.springframework.batch.sample.file.patternmatching.Address;
/**
* Custom class that contains logic that would normally be be contained in

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.multiline;
package org.springframework.batch.sample.file.multilineaggregate;
/**
* A wrapper type for an item that is used by {@link AggregateItemReader} to identify the

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.multiline;
package org.springframework.batch.sample.file.multilineaggregate;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.FieldSet;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.sample.domain.multiline;
package org.springframework.batch.sample.file.multilineaggregate;
import java.util.ArrayList;
import java.util.List;

View File

@@ -0,0 +1,46 @@
## Multiline Aggregate Sample
### About
The goal of this sample is to show some common tricks with multiline
records in file input jobs.
The input file in this case consists of two groups of trades
delimited by special lines in a file (BEGIN and END):
```
BEGIN
UK21341EAH4597898.34customer1
UK21341EAH4611218.12customer2
END
BEGIN
UK21341EAH4724512.78customer2
UK21341EAH4810809.25customer3
UK21341EAH4985423.39customer4
END
```
The goal of the job is to operate on the two groups, so the item
type is naturally `List<Trade`>. To get these items delivered
from an item reader we employ two components from Spring Batch: the
`AggregateItemReader` and the
`PrefixMatchingCompositeLineTokenizer`. The latter is
responsible for recognising the difference between the trade data
and the delimiter records. The former is responsible for
aggregating the trades from each group into a `List` and handing
out the list from its `read()` method. To help these components
perform their responsibilities we also provide some business
knowledge about the data in the form of a `FieldSetMapper`
(`TradeFieldSetMapper`). The `TradeFieldSetMapper` checks
its input for the delimiter fields (BEGIN, END) and if it detects
them, returns the special tokens that `AggregateItemReader`
needs. Otherwise it maps the input into a `Trade` object.
### Run the sample
You can run the sample from the command line as following:
```
$>cd spring-batch-samples
$>../mvnw -Dtest=MultilineAggregateJobFunctionalTests#testJobLaunch test
```

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order;
package org.springframework.batch.sample.file.patternmatching;
public class Address {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order;
package org.springframework.batch.sample.file.patternmatching;
public class BillingInfo {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order;
package org.springframework.batch.sample.file.patternmatching;
public class Customer {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order;
package org.springframework.batch.sample.file.patternmatching;
import java.math.BigDecimal;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order;
package org.springframework.batch.sample.file.patternmatching;
import java.math.BigDecimal;
import java.util.Date;

View File

@@ -0,0 +1,53 @@
### Pattern Matching Sample
## About
The goal is to demonstrate how to handle a more complex file input
format, where a record meant for processing includes nested records
and spans multiple lines.
The input source is a file with multiline records:
```
HEA;0013100345;2007-02-15
NCU;Smith;Peter;;T;20014539;F
BAD;;Oak Street 31/A;;Small Town;00235;IL;US
SAD;Smith, Elizabeth;Elm Street 17;;Some City;30011;FL;United States
BIN;VISA;VISA-12345678903
LIT;1044391041;37.49;0;0;4.99;2.99;1;45.47
LIT;2134776319;221.99;5;0;7.99;2.99;1;221.87
SIN;UPS;EXP;DELIVER ONLY ON WEEKDAYS
FOT;2;2;267.34
HEA;0013100346;2007-02-15
BCU;Acme Factory of England;72155919;T
BAD;;St. Andrews Road 31;;London;55342;;UK
BIN;AMEX;AMEX-72345678903
LIT;1044319101;1070.50;5;0;7.99;2.99;12;12335.46
LIT;2134727219;21.79;5;0;7.99;2.99;12;380.17
LIT;1044339301;79.95;0;5.5;4.99;2.99;4;329.72
LIT;2134747319;55.29;10;0;7.99;2.99;6;364.45
LIT;1044359501;339.99;10;0;7.99;2.99;2;633.94
SIN;FEDX;AMS;
FOT;5;36;14043.74
```
`OrderItemReader` is an example of a non-default programmatic
item reader. It reads input until it detects that the multiline
record has finished and encapsulates the record in a single domain
object.
The output target is a file with multiline records. The concrete
`ItemWriter` passes the object to a an injected 'delegate
writer' which in this case writes the output to a file. The writer
in this case demonstrates how to write multiline output using a
custom aggregator transformer.
## Run the sample
You can run the sample from the command line as following:
```
$>cd spring-batch-samples
$>../mvnw -Dtest=PatternMatchingJobFunctionalTests#testJobLaunch test
```

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order;
package org.springframework.batch.sample.file.patternmatching;
public class ShippingInfo {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal;
package org.springframework.batch.sample.file.patternmatching.internal;
import java.util.ArrayList;
@@ -23,12 +23,12 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.FieldSet;
import org.springframework.batch.sample.domain.order.Address;
import org.springframework.batch.sample.domain.order.BillingInfo;
import org.springframework.batch.sample.domain.order.Customer;
import org.springframework.batch.sample.domain.order.LineItem;
import org.springframework.batch.sample.domain.order.Order;
import org.springframework.batch.sample.domain.order.ShippingInfo;
import org.springframework.batch.sample.file.patternmatching.Address;
import org.springframework.batch.sample.file.patternmatching.BillingInfo;
import org.springframework.batch.sample.file.patternmatching.Customer;
import org.springframework.batch.sample.file.patternmatching.LineItem;
import org.springframework.batch.sample.file.patternmatching.Order;
import org.springframework.batch.sample.file.patternmatching.ShippingInfo;
import org.springframework.lang.Nullable;
/**

View File

@@ -14,13 +14,13 @@
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal;
package org.springframework.batch.sample.file.patternmatching.internal;
import java.util.Map;
import org.springframework.batch.item.file.transform.LineAggregator;
import org.springframework.batch.sample.domain.order.LineItem;
import org.springframework.batch.sample.domain.order.Order;
import org.springframework.batch.sample.file.patternmatching.LineItem;
import org.springframework.batch.sample.file.patternmatching.Order;
/**
* Converts <code>Order</code> object to a list of strings.

View File

@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.extractor;
package org.springframework.batch.sample.file.patternmatching.internal.extractor;
import org.springframework.batch.item.file.transform.FieldExtractor;
import org.springframework.batch.sample.domain.order.Address;
import org.springframework.batch.sample.domain.order.Order;
import org.springframework.batch.sample.file.patternmatching.Address;
import org.springframework.batch.sample.file.patternmatching.Order;
/**
* @author Dan Garrette

View File

@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.extractor;
package org.springframework.batch.sample.file.patternmatching.internal.extractor;
import org.springframework.batch.item.file.transform.FieldExtractor;
import org.springframework.batch.sample.domain.order.BillingInfo;
import org.springframework.batch.sample.domain.order.Order;
import org.springframework.batch.sample.file.patternmatching.BillingInfo;
import org.springframework.batch.sample.file.patternmatching.Order;
/**
* @author Dan Garrette

View File

@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.extractor;
package org.springframework.batch.sample.file.patternmatching.internal.extractor;
import org.springframework.batch.item.file.transform.FieldExtractor;
import org.springframework.batch.sample.domain.order.Customer;
import org.springframework.batch.sample.domain.order.Order;
import org.springframework.batch.sample.file.patternmatching.Customer;
import org.springframework.batch.sample.file.patternmatching.Order;
/**
* @author Dan Garrette

View File

@@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.extractor;
package org.springframework.batch.sample.file.patternmatching.internal.extractor;
import org.springframework.batch.item.file.transform.FieldExtractor;
import org.springframework.batch.sample.domain.order.Order;
import org.springframework.batch.sample.file.patternmatching.Order;
/**
* @author Dan Garrette

View File

@@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.extractor;
package org.springframework.batch.sample.file.patternmatching.internal.extractor;
import java.text.SimpleDateFormat;
import org.springframework.batch.item.file.transform.FieldExtractor;
import org.springframework.batch.sample.domain.order.Order;
import org.springframework.batch.sample.file.patternmatching.Order;
/**
* @author Dan Garrette

View File

@@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.extractor;
package org.springframework.batch.sample.file.patternmatching.internal.extractor;
import org.springframework.batch.item.file.transform.FieldExtractor;
import org.springframework.batch.sample.domain.order.LineItem;
import org.springframework.batch.sample.file.patternmatching.LineItem;
/**
* @author Dan Garrette

View File

@@ -14,11 +14,11 @@
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.mapper;
package org.springframework.batch.sample.file.patternmatching.internal.mapper;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.FieldSet;
import org.springframework.batch.sample.domain.order.Address;
import org.springframework.batch.sample.file.patternmatching.Address;
public class AddressFieldSetMapper implements FieldSetMapper<Address> {

View File

@@ -14,11 +14,11 @@
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.mapper;
package org.springframework.batch.sample.file.patternmatching.internal.mapper;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.FieldSet;
import org.springframework.batch.sample.domain.order.BillingInfo;
import org.springframework.batch.sample.file.patternmatching.BillingInfo;
public class BillingFieldSetMapper implements FieldSetMapper<BillingInfo> {

View File

@@ -14,11 +14,11 @@
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.mapper;
package org.springframework.batch.sample.file.patternmatching.internal.mapper;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.FieldSet;
import org.springframework.batch.sample.domain.order.Customer;
import org.springframework.batch.sample.file.patternmatching.Customer;
public class CustomerFieldSetMapper implements FieldSetMapper<Customer> {

View File

@@ -14,11 +14,11 @@
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.mapper;
package org.springframework.batch.sample.file.patternmatching.internal.mapper;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.FieldSet;
import org.springframework.batch.sample.domain.order.Order;
import org.springframework.batch.sample.file.patternmatching.Order;
public class HeaderFieldSetMapper implements FieldSetMapper<Order> {

View File

@@ -14,11 +14,11 @@
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.mapper;
package org.springframework.batch.sample.file.patternmatching.internal.mapper;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.FieldSet;
import org.springframework.batch.sample.domain.order.LineItem;
import org.springframework.batch.sample.file.patternmatching.LineItem;
public class OrderItemFieldSetMapper implements FieldSetMapper<LineItem> {

View File

@@ -14,11 +14,11 @@
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.mapper;
package org.springframework.batch.sample.file.patternmatching.internal.mapper;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.FieldSet;
import org.springframework.batch.sample.domain.order.ShippingInfo;
import org.springframework.batch.sample.file.patternmatching.ShippingInfo;
public class ShippingFieldSetMapper implements FieldSetMapper<ShippingInfo> {

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.validator;
package org.springframework.batch.sample.file.patternmatching.internal.validator;
import java.math.BigDecimal;
import java.math.RoundingMode;
@@ -21,12 +21,12 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.springframework.batch.sample.domain.order.Address;
import org.springframework.batch.sample.domain.order.BillingInfo;
import org.springframework.batch.sample.domain.order.Customer;
import org.springframework.batch.sample.domain.order.LineItem;
import org.springframework.batch.sample.domain.order.Order;
import org.springframework.batch.sample.domain.order.ShippingInfo;
import org.springframework.batch.sample.file.patternmatching.Address;
import org.springframework.batch.sample.file.patternmatching.BillingInfo;
import org.springframework.batch.sample.file.patternmatching.Customer;
import org.springframework.batch.sample.file.patternmatching.LineItem;
import org.springframework.batch.sample.file.patternmatching.Order;
import org.springframework.batch.sample.file.patternmatching.ShippingInfo;
import org.springframework.util.StringUtils;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.xml;
package org.springframework.batch.sample.file.patternmatching.internal.xml;
/**
* An XML customer.

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.xml;
package org.springframework.batch.sample.file.patternmatching.internal.xml;
/**
* An XML line-item.

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.xml;
package org.springframework.batch.sample.file.patternmatching.internal.xml;
import java.util.Date;
import java.util.List;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.sample.domain.order.internal.xml;
package org.springframework.batch.sample.file.patternmatching.internal.xml;
/**
* An XML shipper.

View File

@@ -0,0 +1,16 @@
## Customer Filter Sample
### About
This shows the use of the `ItemProcessor` to filter out items by
returning null. When an item is filtered it leads to an increment
in the `filterCount` in the step execution.
### Run the sample
You can run the sample from the command line as following:
```
$>cd spring-batch-samples
$>../mvnw -Dtest=CustomerFilterJobFunctionalTests#testFilterJob test
```

View File

@@ -0,0 +1,20 @@
## Header Footer Sample
### About
This sample shows the use of callbacks and listeners to deal with
headers and footers in flat files. It uses two custom callbacks:
* `HeaderCopyCallback`: copies the header of a file from the
input to the output.
* `SummaryFooterCallback`: creates a summary footer at the end
of the output file.
### Run the sample
You can run the sample from the command line as following:
```
$>cd spring-batch-samples
$>../mvnw -Dtest=HeaderFooterSampleFunctionalTests#testJob test
```

View File

@@ -0,0 +1,14 @@
## Job Step sample
### About
This sample shows how to use a step to launch a (sub) job.
### Run the sample
You can run the sample from the command line as following:
```
$>cd spring-batch-samples
$>../mvnw -Dtest=JobStepFunctionalTests#testJobLaunch test
```

View File

@@ -0,0 +1,15 @@
### Loop Flow Sample
## About
Shows how to implement a job that repeats one of its steps up to a
limit set by a `JobExecutionDecider`.
## Run the samples
You can run the sample from the command line as following:
```
$>cd spring-batch-samples
$>../mvnw -Dtest=LoopFlowSampleFunctionalTests#testJobLaunch test
```

View File

@@ -0,0 +1,15 @@
## Mail writer sample
### About
This sample shows how to use the `SimpleMailMessageItemWriter` to send
emails in a step.
### Run the sample
You can run the sample from the command line as following:
```
$>cd spring-batch-samples
$>../mvnw -Dtest=MailJobFunctionalTests#testLaunchJob test
```

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.mail.internal;
package org.springframework.batch.sample.mail;
import java.util.ArrayList;
import java.util.List;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.mail.internal;
package org.springframework.batch.sample.mail;
import java.util.ArrayList;
import java.util.LinkedHashMap;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.mail;
package org.springframework.batch.sample.mail;
/**
* @author Dan Garrette

View File

@@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.domain.mail.internal;
package org.springframework.batch.sample.mail;
import java.util.Date;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.sample.domain.mail.User;
import org.springframework.batch.sample.mail.User;
import org.springframework.lang.Nullable;
import org.springframework.mail.SimpleMailMessage;

View File

@@ -0,0 +1,14 @@
## Groovy sample
### About
This sample shows how to adapt and use a Groovy script as a `Tasklet`.
### Run the sample
You can run the sample from the command line as following:
```
$>cd spring-batch-samples
$>../mvnw -Dtest=GroovyJobFunctionalTests#testLaunchJob test
```

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.sample.common;
package org.springframework.batch.sample.misc.jmx;
import org.springframework.batch.item.ItemReader;
import org.springframework.lang.Nullable;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.sample.common;
package org.springframework.batch.sample.misc.jmx;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.sample.jmx;
package org.springframework.batch.sample.misc.jmx;
import javax.management.Notification;

View File

@@ -0,0 +1,27 @@
## Adhoc Loop and JMX Sample
### About
This job is simply an infinite loop. It runs forever so it is
useful for testing features to do with stopping and starting jobs.
It is used, for instance, as one of the jobs that can be run from JMX.
The JMX launcher uses an additional XML configuration file
(`adhoc-job-launcher-context.xml`) to set up a `JobOperator` for
running jobs asynchronously (i.e. in a background thread).
The rest of the configuration for this demo consists of exposing
some components from the application context as JMX managed beans.
The `JobOperator` is exposed so that it can be controlled from a
remote client (such as JConsole from the JDK) which does not have
Spring Batch on the classpath. See the Spring Core Reference Guide
for more details on how to customise the JMX configuration.
### Run the sample
You can run the sample from the command line as following:
```
$>cd spring-batch-samples
$>../mvnw -Dtest=RemoteLauncherTests#testPauseJob test
```

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.sample.jmx;
package org.springframework.batch.sample.misc.jmx;
import org.springframework.context.ApplicationEvent;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.quartz;
package org.springframework.batch.sample.misc.quartz;
import java.util.Date;
import java.util.Map;

View File

@@ -0,0 +1,75 @@
## Quartz Sample
FIXME: Update job configuration and classes imported from Spring Framework
### About
The goal is to demonstrate how to schedule job execution using
Quartz scheduler. In this case there is no unit test to launch the
sample because it just re-uses the football job. There is a main
method in `JobRegistryBackgroundJobRunner` and an Eclipse launch
configuration which runs it with arguments to pick up the football
job.
The additional XML configuration for this job is in
`quartz-job-launcher.xml`, and it also re-uses
`footballJob.xml`
The configuration declares a `JobLauncher` bean. The launcher
bean is different from the other samples only in that it uses an
asynchronous task executor, so that the jobs are launched in a
separate thread to the main method:
```xml
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.TaskExecutorJobLauncher">
<property name="jobRepository" ref="jobRepository" />
<property name="taskExecutor">
<bean class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
</property>
</bean>
```
Also, a Quartz `JobDetail` is defined using a Spring
`JobDetailBean` as a convenience.
```xml
<bean id="jobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="org.springframework.batch.sample.misc.quartz.JobLauncherDetails" />
<property name="group" value="quartz-batch" />
<property name="jobDataAsMap">
<map>
<entry key="jobName" value="footballJob"/>
<entry key="jobLocator" value-ref="jobRegistry"/>
<entry key="jobLauncher" value-ref="jobLauncher"/>
</map>
</property>
</bean>
```
Finally, a trigger with a scheduler is defined that will launch the
job detail every 10 seconds:
```xml
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="jobDetail" />
<property name="cronExpression" value="0/10 * * * * ?" />
</bean>
</property>
</bean>
```
The job is thus scheduled to run every 10 seconds. In fact it
should be successful on the first attempt, so the second and
subsequent attempts should through a
`JobInstanceAlreadyCompleteException`. In a production system,
the job detail would probably be modified to account for this
exception (e.g. catch it and re-submit with a new set of job
parameters). The point here is that Spring Batch guarantees that
the job execution is idempotent - you can never inadvertently
process the same data twice.
## Run the sample
TODO

View File

@@ -28,7 +28,7 @@ import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;
@Configuration
@PropertySource("classpath:/mongodb-sample.properties")
@PropertySource("classpath:/org/springframework/batch/sample/mongodb/mongodb-sample.properties")
public class MongoDBConfiguration {
@Value("${mongodb.host}")

View File

@@ -0,0 +1,22 @@
## Local Partitioning Sample
### About
The purpose of this sample is to show multi-threaded step execution
using the `PartitionHandler` SPI. The example uses a
`TaskExecutorPartitionHandler` to spread the work of reading
some files across multiple threads, with one `Step` execution
per thread. The key components are the `PartitionStep` and the
`MultiResourcePartitioner` which is responsible for dividing up
the work. Notice that the readers and writers in the `Step`
that is being partitioned are step-scoped, so that their state does
not get shared across threads of execution.
### Run the sample
You can run the sample from the command line as following:
```
$>cd spring-batch-samples
$>../mvnw -Dtest=MailJobFunctionalTests#testLaunchJob test
```

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.sample.remotepartitioning;
package org.springframework.batch.sample.partitioning.remote;
import java.util.Map;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.sample.remotepartitioning;
package org.springframework.batch.sample.partitioning.remote;
import jakarta.jms.JMSException;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
@@ -28,7 +28,7 @@ import org.springframework.context.annotation.PropertySource;
* @author Mahmoud Ben Hassine
*/
@Configuration
@PropertySource("classpath:remote-partitioning.properties")
@PropertySource("classpath:org/springframework/batch/sample/partitioning/remote/remote-partitioning.properties")
public class BrokerConfiguration {
@Value("${broker.url}")

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.sample.remotepartitioning;
package org.springframework.batch.sample.partitioning.remote;
import javax.sql.DataSource;
@@ -30,7 +30,7 @@ import org.springframework.jdbc.support.JdbcTransactionManager;
* @author Mahmoud Ben Hassine
*/
@Configuration
@PropertySource("classpath:remote-partitioning.properties")
@PropertySource("classpath:org/springframework/batch/sample/partitioning/remote/remote-partitioning.properties")
public class DataSourceConfiguration {
@Value("${datasource.url}")

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.remotepartitioning.aggregating;
package org.springframework.batch.sample.partitioning.remote.aggregating;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
@@ -24,9 +24,9 @@ import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.integration.config.annotation.EnableBatchIntegration;
import org.springframework.batch.integration.partition.RemotePartitioningManagerStepBuilderFactory;
import org.springframework.batch.sample.remotepartitioning.BasicPartitioner;
import org.springframework.batch.sample.remotepartitioning.BrokerConfiguration;
import org.springframework.batch.sample.remotepartitioning.DataSourceConfiguration;
import org.springframework.batch.sample.partitioning.remote.BasicPartitioner;
import org.springframework.batch.sample.partitioning.remote.BrokerConfiguration;
import org.springframework.batch.sample.partitioning.remote.DataSourceConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.remotepartitioning.aggregating;
package org.springframework.batch.sample.partitioning.remote.aggregating;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
@@ -24,8 +24,8 @@ import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.integration.config.annotation.EnableBatchIntegration;
import org.springframework.batch.integration.partition.RemotePartitioningWorkerStepBuilderFactory;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.sample.remotepartitioning.BrokerConfiguration;
import org.springframework.batch.sample.remotepartitioning.DataSourceConfiguration;
import org.springframework.batch.sample.partitioning.remote.BrokerConfiguration;
import org.springframework.batch.sample.partitioning.remote.DataSourceConfiguration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.remotepartitioning.polling;
package org.springframework.batch.sample.partitioning.remote.polling;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
@@ -24,9 +24,9 @@ import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.integration.config.annotation.EnableBatchIntegration;
import org.springframework.batch.integration.partition.RemotePartitioningManagerStepBuilderFactory;
import org.springframework.batch.sample.remotepartitioning.BasicPartitioner;
import org.springframework.batch.sample.remotepartitioning.BrokerConfiguration;
import org.springframework.batch.sample.remotepartitioning.DataSourceConfiguration;
import org.springframework.batch.sample.partitioning.remote.BasicPartitioner;
import org.springframework.batch.sample.partitioning.remote.BrokerConfiguration;
import org.springframework.batch.sample.partitioning.remote.DataSourceConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.remotepartitioning.polling;
package org.springframework.batch.sample.partitioning.remote.polling;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
@@ -24,8 +24,8 @@ import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.integration.config.annotation.EnableBatchIntegration;
import org.springframework.batch.integration.partition.RemotePartitioningWorkerStepBuilderFactory;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.sample.remotepartitioning.BrokerConfiguration;
import org.springframework.batch.sample.remotepartitioning.DataSourceConfiguration;
import org.springframework.batch.sample.partitioning.remote.BrokerConfiguration;
import org.springframework.batch.sample.partitioning.remote.DataSourceConfiguration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

View File

@@ -0,0 +1,61 @@
## Process Indicator pattern Sample
## About
The purpose of this sample is to show multi-threaded step execution
using the Process Indicator pattern.
The job reads data from the a fixed length file , but instead of
writing it out directly it goes through a staging table, and the
staging table is read in a multi-threaded step. Note that for such
a simple example where the item processing was not expensive, there
is unlikely to be much if any benefit in using a multi-threaded
step.
Multi-threaded step execution is easy to configure using Spring
Batch, but there are some limitations. Most of the out-of-the-box
`ItemReader` and `ItemWriter` implementations are not
designed to work in this scenario because they need to be
restartable and they are also stateful. There should be no surprise
about this, and reading a file (for instance) is usually fast enough
that multi-threading that part of the process is not likely to
provide much benefit, compared to the cost of managing the state.
The best strategy to cope with restart state from multiple
concurrent threads depends on the kind of input source involved:
* For file-based input (and output) restart sate is practically
impossible to manage. Spring Batch does not provide any features
or samples to help with this use case.
* With message middleware input it is trivial to manage restarts,
since there is no state to store (if a transaction rolls back the
messages are returned to the destination they came from).
* With database input state management is still necessary, but it
isn't particularly difficult. The easiest thing to do is rely on
a Process Indicator in the input data, which is a column in the
data indicating for each row if it has been processed or not. The
flag is updated inside the batch transaction, and then in the case
of a failure the updates are lost, and the records will show as
un-processed on a restart.
This last strategy is implemented in the `StagingItemReader`.
Its companion, the `StagingItemWriter` is responsible for
setting up the data in a staging table which contains the process
indicator. The reader is then driven by a simple SQL query that
includes a where clause for the processed flag, i.e.
```sql
SELECT ID FROM BATCH_STAGING WHERE JOB_ID=? AND PROCESSED=? ORDER BY ID
```
It is then responsible for updating the processed flag (which
happens inside the main step transaction).
## Run the sample
You can run the sample from the command line as following:
```
$>cd spring-batch-samples
$>../mvnw -Dtest=ProcessIndicatorJobFunctionalTests#testLaunchJob test
```

View File

@@ -0,0 +1,22 @@
## Fail / Restart Sample
### About
The goal of this sample is to show how a job can be restarted after
a failure and continue processing where it left off.
To simulate a failure we "fake" a failure on the fourth record
though the use of a sample component
`ExceptionThrowingItemReaderProxy`. This is a stateful reader
that counts how many records it has processed and throws a planned
exception in a specified place. Since we re-use the same instance
when we restart the job it will not fail the second time.
### Run the sample
You can run the sample from the command line as following:
```
$>cd spring-batch-samples
$>../mvnw -Dtest=RestartFunctionalTests#testLaunchJob test
```

View File

@@ -0,0 +1,16 @@
## Stop / Restart Sample
### About
This sample has a single step that is an infinite loop, reading and
writing fake data. It is used to demonstrate stop signals and
restart capabilities.
### Run the sample
You can run the sample from the command line as following:
```
$>cd spring-batch-samples
$>../mvnw -Dtest=JobOperatorFunctionalTests#testStartStopResumeJob test
```

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.sample.config;
package org.springframework.batch.sample.retry;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;

View File

@@ -0,0 +1,28 @@
## Trade Job
### About
The goal is to show a reasonably complex scenario, that would
resemble the real-life usage of the framework.
This job has 3 steps:
```mermaid
graph LR
A(tradeLoad) --> B(decreaseCredit)
B --> C(generateReport)
```
First, data about trades are imported from a
file to database. Second, the trades are read from the database and
credit on customer accounts is decreased appropriately. Last, a
report about customers is exported to a file.
## Run the sample
You can run the sample from the command line as following:
```
$>cd spring-batch-samples
$>../mvnw -Dtest=TradeJobFunctionalTests#testLaunchJob test
```

View File

@@ -44,11 +44,11 @@
</bean>
<bean id="value"
class="org.springframework.batch.sample.TaskletJobFunctionalTests$TestBean"
class="org.springframework.batch.sample.adapter.tasklet.TaskletAdapterJobFunctionalTests$TestBean"
scope="step">
<property name="value" value="#{jobParameters[value]}" />
</bean>
<bean id="task" class="org.springframework.batch.sample.TaskletJobFunctionalTests$Task"/>
<bean id="task" class="org.springframework.batch.sample.adapter.tasklet.Task"/>
</beans>

View File

@@ -8,8 +8,7 @@
xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="classpath:org/springframework/batch/sample/rabbitmq/default.amqp.properties" />
<beans:import resource="classpath:org/springframework/batch/sample/rabbitmq/job/rabbitmq-beans.xml"/>
<beans:import resource="classpath:org/springframework/batch/sample/amqp/job/rabbitmq-beans.xml"/>
<batch:job id="amqp-example-job">
<batch:step id="processQueue">
@@ -23,7 +22,7 @@
<beans:constructor-arg ref="inboundAmqpTemplate"/>
</beans:bean>
<beans:bean id="amqpItemProcessor" class="org.springframework.batch.sample.rabbitmq.processor.MessageProcessor"/>
<beans:bean id="amqpItemProcessor" class="org.springframework.batch.sample.amqp.MessageProcessor"/>
<beans:bean id="amqpItemWriter" class="org.springframework.batch.item.amqp.AmqpItemWriter">
<beans:constructor-arg ref="outboundAmqpTemplate"/>

View File

@@ -4,10 +4,13 @@
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/rabbit https://www.springframework.org/schema/rabbit/spring-rabbit.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="classpath:org/springframework/batch/sample/amqp/default.amqp.properties" />
<rabbit:connection-factory id="rabbitConnectionFactory" port="${rabbitmq.port}" host="${rabbitmq.host}"/>
<rabbit:admin connection-factory="rabbitConnectionFactory"/>

View File

@@ -24,7 +24,7 @@
<bean id="tradeFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader">
<property name="resource"
value="classpath:data/beanWrapperMapperSampleJob/input/20070122.teststream.ImportTradeDataStep.txt" />
value="classpath:org/springframework/batch/sample/beanwrapper/data/ImportTradeDataStep.txt" />
<property name="lineMapper">
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<property name="lineTokenizer" ref="tradeTokenizer" />
@@ -35,7 +35,7 @@
<bean id="personFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader">
<property name="resource"
value="classpath:data/beanWrapperMapperSampleJob/input/20070122.teststream.ImportPersonDataStep.txt" />
value="classpath:org/springframework/batch/sample/beanwrapper/data/ImportPersonDataStep.txt" />
<property name="lineMapper">
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<property name="lineTokenizer" ref="personTokenizer" />

View File

@@ -42,7 +42,7 @@
<bean id="fileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader">
<property name="resource"
value="classpath:data/fixedLengthImportJob/input/20070122.teststream.ImportTradeDataStep.txt" />
value="classpath:org/springframework/batch/sample/compositewriter/data/ImportTradeDataStep.txt" />
<property name="lineMapper">
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<property name="lineTokenizer" ref="fixedFileTokenizer" />

View File

@@ -17,13 +17,13 @@
</job>
<bean id="reader"
class="org.springframework.batch.sample.domain.multiline.AggregateItemReader">
class="org.springframework.batch.sample.file.multilineaggregate.AggregateItemReader">
<property name="itemReader" ref="fileItemReader" />
</bean>
<bean id="writer" class="org.springframework.batch.item.file.FlatFileItemWriter">
<property name="resource"
value="file:target/test-outputs/20070122.testStream.multilineStep.txt" />
value="file:target/test-outputs/multilineStep-output.txt" />
<property name="lineAggregator">
<bean
class="org.springframework.batch.item.file.transform.PassThroughLineAggregator" />
@@ -32,13 +32,13 @@
<bean id="fileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader">
<property name="resource"
value="classpath:data/multilineJob/input/20070122.teststream.multilineStep.txt" />
value="classpath:org/springframework/batch/sample/file/multilineaggregate/data/multilineStep.txt" />
<property name="lineMapper">
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<property name="lineTokenizer" ref="fixedFileDescriptor" />
<property name="fieldSetMapper">
<bean
class="org.springframework.batch.sample.domain.multiline.AggregateItemFieldSetMapper">
class="org.springframework.batch.sample.file.multilineaggregate.AggregateItemFieldSetMapper">
<property name="delegate" ref="tradeLineMapper" />
</bean>
</property>

View File

@@ -23,7 +23,7 @@
</step>
</job>
<bean id="reader" class="org.springframework.batch.sample.domain.order.internal.OrderItemReader">
<bean id="reader" class="org.springframework.batch.sample.file.patternmatching.internal.OrderItemReader">
<property name="fieldSetReader" ref="fileItemReader" />
<property name="headerMapper" ref="headerFieldSetMapper" />
<property name="customerMapper" ref="customerFieldSetMapper" />
@@ -34,7 +34,7 @@
</bean>
<bean id="fileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader">
<property name="resource" value="data/multilineOrderJob/input/multilineOrderInput.txt" />
<property name="resource" value="classpath:org/springframework/batch/sample/file/patternmatching/data/multilineOrderInput.txt" />
<property name="lineMapper">
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<property name="lineTokenizer" ref="orderFileTokenizer" />
@@ -45,12 +45,12 @@
</property>
</bean>
<bean id="headerFieldSetMapper" class="org.springframework.batch.sample.domain.order.internal.mapper.HeaderFieldSetMapper" />
<bean id="customerFieldSetMapper" class="org.springframework.batch.sample.domain.order.internal.mapper.CustomerFieldSetMapper" />
<bean id="addressFieldSetMapper" class="org.springframework.batch.sample.domain.order.internal.mapper.AddressFieldSetMapper" />
<bean id="billingFieldSetMapper" class="org.springframework.batch.sample.domain.order.internal.mapper.BillingFieldSetMapper" />
<bean id="orderItemFieldSetMapper" class="org.springframework.batch.sample.domain.order.internal.mapper.OrderItemFieldSetMapper" />
<bean id="shippingFieldSetMapper" class="org.springframework.batch.sample.domain.order.internal.mapper.ShippingFieldSetMapper" />
<bean id="headerFieldSetMapper" class="org.springframework.batch.sample.file.patternmatching.internal.mapper.HeaderFieldSetMapper" />
<bean id="customerFieldSetMapper" class="org.springframework.batch.sample.file.patternmatching.internal.mapper.CustomerFieldSetMapper" />
<bean id="addressFieldSetMapper" class="org.springframework.batch.sample.file.patternmatching.internal.mapper.AddressFieldSetMapper" />
<bean id="billingFieldSetMapper" class="org.springframework.batch.sample.file.patternmatching.internal.mapper.BillingFieldSetMapper" />
<bean id="orderItemFieldSetMapper" class="org.springframework.batch.sample.file.patternmatching.internal.mapper.OrderItemFieldSetMapper" />
<bean id="shippingFieldSetMapper" class="org.springframework.batch.sample.file.patternmatching.internal.mapper.ShippingFieldSetMapper" />
<bean id="processor" class="org.springframework.batch.item.validator.ValidatingItemProcessor">
<constructor-arg ref="validator" />
@@ -60,7 +60,7 @@
<bean id="fileItemWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
<property name="resource" value="file:target/test-outputs/multilineOrderOutput.txt" />
<property name="lineAggregator">
<bean class="org.springframework.batch.sample.domain.order.internal.OrderLineAggregator">
<bean class="org.springframework.batch.sample.file.patternmatching.internal.OrderLineAggregator">
<property name="aggregators" ref="outputAggregators"/>
</bean>
</property>

View File

@@ -19,42 +19,42 @@
<bean id="outputHeader" parent="baseAggregator">
<property name="format" value="%-12s%-10s%-30s"/>
<property name="fieldExtractor">
<bean class="org.springframework.batch.sample.domain.order.internal.extractor.HeaderFieldExtractor"/>
<bean class="org.springframework.batch.sample.file.patternmatching.internal.extractor.HeaderFieldExtractor"/>
</property>
</bean>
<bean id="outputFooter" parent="baseAggregator">
<property name="format" value="%-10s%20s"/>
<property name="fieldExtractor">
<bean class="org.springframework.batch.sample.domain.order.internal.extractor.FooterFieldExtractor"/>
<bean class="org.springframework.batch.sample.file.patternmatching.internal.extractor.FooterFieldExtractor"/>
</property>
</bean>
<bean id="outputCustomer" parent="baseAggregator">
<property name="format" value="%-9s%-10s%-10s%-10s%-10s"/>
<property name="fieldExtractor">
<bean class="org.springframework.batch.sample.domain.order.internal.extractor.CustomerFieldExtractor"/>
<bean class="org.springframework.batch.sample.file.patternmatching.internal.extractor.CustomerFieldExtractor"/>
</property>
</bean>
<bean id="outputAddress" parent="baseAggregator">
<property name="format" value="%-8s%-20s%-10s%-10s"/>
<property name="fieldExtractor">
<bean class="org.springframework.batch.sample.domain.order.internal.extractor.AddressFieldExtractor"/>
<bean class="org.springframework.batch.sample.file.patternmatching.internal.extractor.AddressFieldExtractor"/>
</property>
</bean>
<bean id="outputBilling" parent="baseAggregator">
<property name="format" value="%-8s%-10s%-20s"/>
<property name="fieldExtractor">
<bean class="org.springframework.batch.sample.domain.order.internal.extractor.BillingInfoFieldExtractor"/>
<bean class="org.springframework.batch.sample.file.patternmatching.internal.extractor.BillingInfoFieldExtractor"/>
</property>
</bean>
<bean id="outputLineItem" parent="baseAggregator">
<property name="format" value="%-5s%-10s%-10s"/>
<property name="fieldExtractor">
<bean class="org.springframework.batch.sample.domain.order.internal.extractor.LineItemFieldExtractor"/>
<bean class="org.springframework.batch.sample.file.patternmatching.internal.extractor.LineItemFieldExtractor"/>
</property>
</bean>
</beans>

View File

@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="validator" class="org.springframework.batch.item.validator.SpringValidator">
<property name="validator">
<bean id="orderValidator" class="org.springframework.batch.sample.domain.order.internal.validator.OrderValidator"/>
</property>
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="validator" class="org.springframework.batch.item.validator.SpringValidator">
<property name="validator">
<bean id="orderValidator" class="org.springframework.batch.sample.file.patternmatching.internal.validator.OrderValidator"/>
</property>
</bean>
</beans>

Some files were not shown because too many files have changed in this diff Show More