Skip to content

Commit 746ffab

Browse files
committed
Update samples
- Restructure contexts - Remove unused resources - Remove irrelevant tests Issue #4329
1 parent f7ec69e commit 746ffab

File tree

105 files changed

+209
-3785
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+209
-3785
lines changed

spring-batch-samples/README.md

Lines changed: 18 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Here is a list of samples with checks to indicate which features each one demons
3131
| [Football Job](#football-job) | | | | | | | | | | | |
3232
| [Trade Job](#trade-job) | | | | | | X | | | | | |
3333
| [Header Footer Sample](#header-footer-sample) | | | | | | | | | | | |
34-
| [Hibernate Sample](#hibernate-sample) | | X | | | | | | X | | | |
3534
| [Loop Flow Sample](#loop-flow-sample) | | | | | | | | | | | |
3635
| [Multiline Sample](#multiline-input-job) | | | | | | | X | | | | |
3736
| [Pattern matching Sample](#pattern-matching-sample) | | | | | | | X | | | | |
@@ -53,7 +52,6 @@ The IO Sample Job has a number of special instances that show different IO featu
5352
|:--------------------------------------------------------------------|:---------------:|:------------------:|:---------:|:---------------:|:---------------:|:----------------:|:-------------------:|:----------:|:---------:|:--------------:|:----------:|:------------:|
5453
| [Delimited File Import Job](#delimited-file-import-job) | x | | | | | | | x | | | | |
5554
| [Fixed Length Import Job](#fixed-length-import-job) | | x | | | | | | | x | | | |
56-
| [Hibernate Sample](#hibernate-sample) | | | | | x | | | | | | x | |
5755
| [Jdbc Readers and Writers Sample](#jdbc-readers-and-writers-sample) | | | | | x | | | | | | x | |
5856
| [JPA Readers and Writers sample](#jpa-readers-and-writers-sample) | | | | x | | | | | | | x | |
5957
| [Multiline Input Sample](#multiline-input-job) | x | | | | | | | x | | | x | |
@@ -327,22 +325,6 @@ of the output file.
327325

328326
[Header Footer Sample](src/main/java/org/springframework/batch/samples/headerfooter/README.md)
329327

330-
### Hibernate Sample
331-
332-
The purpose of this sample is to show a typical usage of Hibernate
333-
as an ORM tool in the input and output of a job.
334-
335-
The job uses a `HibernateCursorItemReader` for the input, where
336-
a simple HQL query is used to supply items. It also uses a
337-
non-framework `ItemWriter` wrapping a DAO, which perhaps was
338-
written as part of an online system.
339-
340-
The output reliability and robustness are improved by the use of
341-
`Session.flush()` inside `ItemWriter.write()`. This
342-
"write-behind" behaviour is provided by Hibernate implicitly, but we
343-
need to take control of it so that the skip and retry features
344-
provided by Spring Batch can work effectively.
345-
346328
### Stop Restart Sample
347329

348330
This sample has a single step that is an infinite loop, reading and
@@ -440,12 +422,14 @@ capabilities of Spring Batch.
440422
The retry is configured in the step through the
441423
`SkipLimitStepFactoryBean`:
442424

443-
<bean id="step1" parent="simpleStep"
444-
class="org.springframework.batch.core.step.item.FaultTolerantStepFactoryBean">
445-
...
446-
<property name="retryLimit" value="3" />
447-
<property name="retryableExceptionClasses" value="java.lang.Exception" />
448-
</bean>
425+
```xml
426+
<bean id="step1" parent="simpleStep"
427+
class="org.springframework.batch.core.step.item.FaultTolerantStepFactoryBean">
428+
...
429+
<property name="retryLimit" value="3" />
430+
<property name="retryableExceptionClasses" value="java.lang.Exception" />
431+
</bean>
432+
```
449433

450434
Failed items will cause a rollback for all `Exception` types, up
451435
to a limit of 3 attempts. On the 4th attempt, the failed item would
@@ -485,13 +469,15 @@ back on the validation exception, since we know that it didn't
485469
invalidate the transaction, only the item. This is done through the
486470
transaction attribute:
487471

488-
<bean id="step2" parent="skipLimitStep">
489-
<property name="skipLimit" value="1" />
490-
<!-- No rollback for exceptions that are marked with "+" in the tx attributes -->
491-
<property name="transactionAttribute"
492-
value="+org.springframework.batch.item.validator.ValidationException" />
493-
....
494-
</bean>
472+
```xml
473+
<bean id="step2" parent="skipLimitStep">
474+
<property name="skipLimit" value="1" />
475+
<!-- No rollback for exceptions that are marked with "+" in the tx attributes -->
476+
<property name="transactionAttribute"
477+
value="+org.springframework.batch.item.validator.ValidationException" />
478+
....
479+
</bean>
480+
```
495481

496482
The format for the transaction attribute specification is given in
497483
the Spring Core documentation (e.g. see the Javadocs for
@@ -563,62 +549,6 @@ during reading and processing can be found in
563549
`org.springframework.batch.samples.skip.SkippableExceptionDuringReadSample`
564550
and `org.springframework.batch.samples.skip.SkippableExceptionDuringProcessSample`.
565551

566-
### Tasklet Job
567-
568-
The goal is to show the simplest use of the batch framework with a
569-
single job with a single step, which cleans up a directory and runs
570-
a system command.
571-
572-
*Description:* The
573-
`Job` itself is defined by the bean definition with
574-
`id="taskletJob"`. In this example we have two steps.
575-
576-
* The first step defines a tasklet that is responsible for
577-
clearing out a directory though a custom `Tasklet`. Each
578-
tasklet has an `execute()` method which is called by the
579-
step. All processing of business data should be handled by this
580-
method.
581-
* The second step uses another tasklet to execute a system (OS)
582-
command line.
583-
584-
You can visualise the Spring configuration of a job through
585-
Spring-IDE. See [Spring IDE](https://spring.io/tools). The
586-
source view of the configuration is as follows:
587-
588-
<bean id="taskletJob" parent="simpleJob">
589-
<property name="steps">
590-
<list>
591-
<bean id="deleteFilesInDir" parent="taskletStep">
592-
<property name="tasklet">
593-
<bean
594-
class="org.springframework.batch.samples.tasklet.FileDeletingTasklet">
595-
<property name="directoryResource" ref="directory" />
596-
</bean>
597-
</property>
598-
</bean>
599-
<bean id="executeSystemCommand" parent="taskletStep">
600-
<property name="tasklet">
601-
<bean
602-
class="org.springframework.batch.samples.common.SystemCommandTasklet">
603-
<property name="command" value="echo hello" />
604-
<!-- 5 second timeout for the command to complete -->
605-
<property name="timeout" value="5000" />
606-
</bean>
607-
</property>
608-
</bean>
609-
</list>
610-
</property>
611-
</bean>
612-
613-
<bean id="directory"
614-
class="org.springframework.core.io.FileSystemResource">
615-
<constructor-arg value="target/test-outputs/test-dir" />
616-
</bean>
617-
618-
For simplicity we are only displaying the job configuration itself
619-
and leaving out the details of the supporting batch execution
620-
environment configuration.
621-
622552
### Batch metrics with Micrometer
623553

624554
This sample shows how to use [Micrometer](https://micrometer.io) to collect batch metrics in Spring Batch.
@@ -650,7 +580,7 @@ and import the ready-to-use dashboard in `spring-batch-samples/src/main/resource
650580
Finally, run the `org.springframework.batch.samples.metrics.BatchMetricsApplication`
651581
class without any argument to start the sample.
652582

653-
# MongoDB sample
583+
### MongoDB sample
654584

655585
This sample is a showcase of MongoDB support in Spring Batch. It copies data from
656586
an input collection to an output collection using `MongoItemReader` and `MongoItemWriter`.

spring-batch-samples/src/main/java/org/springframework/batch/samples/common/LogAdvice.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

spring-batch-samples/src/main/java/org/springframework/batch/samples/common/StepExecutionApplicationEventAdvice.java

Lines changed: 0 additions & 69 deletions
This file was deleted.

spring-batch-samples/src/main/java/org/springframework/batch/samples/config/DataSourceConfiguration.java

Lines changed: 0 additions & 71 deletions
This file was deleted.

spring-batch-samples/src/main/java/org/springframework/batch/samples/football/internal/FootballExceptionHandler.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)