Skip to content

Commit 4f6bbac

Browse files
committed
Add support for in-memory Batch infrastructure
This commit moves the existing JDBC-based Spring Batch infrastructure to a new 'spring-boot-batch-jdbc' module, while the existing module only offers in-memory (aka resourceless) support. The commit also updates the reference guide to provide some more information about what's available and how to use it. Closes gh-46307
1 parent 54ffc42 commit 4f6bbac

File tree

39 files changed

+1900
-1089
lines changed

39 files changed

+1900
-1089
lines changed

documentation/spring-boot-docs/src/docs/antora/modules/ROOT/pages/redirect.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,6 @@
387387
* xref:how-to:batch.adoc#howto.batch.restarting-a-failed-job[#howto.batch.restarting-a-failed-job]
388388
* xref:how-to:batch.adoc#howto.batch.running-from-the-command-line[#howto-spring-batch-running-command-line]
389389
* xref:how-to:batch.adoc#howto.batch.running-from-the-command-line[#howto.batch.running-from-the-command-line]
390-
* xref:how-to:batch.adoc#howto.batch.running-jobs-on-startup[#howto-spring-batch-running-jobs-on-startup]
391-
* xref:how-to:batch.adoc#howto.batch.running-jobs-on-startup[#howto.batch.running-jobs-on-startup]
392390
* xref:how-to:batch.adoc#howto.batch.specifying-a-data-source[#howto-spring-batch-specifying-a-data-source]
393391
* xref:how-to:batch.adoc#howto.batch.specifying-a-data-source[#howto.batch.specifying-a-data-source]
394392
* xref:how-to:batch.adoc#howto.batch.specifying-a-transaction-manager[#howto.batch.specifying-a-transaction-manager]
@@ -1633,6 +1631,8 @@
16331631
* xref:reference:features/ssl.adoc#features.ssl[#features.ssl]
16341632
* xref:reference:features/task-execution-and-scheduling.adoc#features.task-execution-and-scheduling[#boot-features-task-execution-scheduling]
16351633
* xref:reference:features/task-execution-and-scheduling.adoc#features.task-execution-and-scheduling[#features.task-execution-and-scheduling]
1634+
* xref:reference:io/spring-batch.adoc#io.spring-batch.running-jobs-on-startup[#howto-spring-batch-running-jobs-on-startup]
1635+
* xref:reference:io/spring-batch.adoc#io.spring-batch.running-jobs-on-startup[#howto.batch.running-jobs-on-startup]
16361636
* xref:reference:io/caching.adoc#io.caching.provider.cache2k[#io.caching.provider.cache2k]
16371637
* xref:reference:io/caching.adoc#io.caching.provider.caffeine[#boot-features-caching-provider-caffeine]
16381638
* xref:reference:io/caching.adoc#io.caching.provider.caffeine[#features.caching.provider.caffeine]

documentation/spring-boot-docs/src/docs/antora/modules/how-to/pages/batch.adoc

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,6 @@ If you do so and want two task executors (for example by retaining the auto-conf
3737

3838

3939

40-
[[howto.batch.running-jobs-on-startup]]
41-
== Running Spring Batch Jobs on Startup
42-
43-
Spring Batch auto-configuration is enabled by adding `spring-boot-starter-batch` to your application's classpath.
44-
45-
If a single javadoc:org.springframework.batch.core.Job[] bean is found in the application context, it is executed on startup (see javadoc:org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner[] for details).
46-
If multiple javadoc:org.springframework.batch.core.Job[] beans are found, the job that should be executed must be specified using configprop:spring.batch.job.name[].
47-
48-
To disable running a javadoc:org.springframework.batch.core.Job[] found in the application context, set the configprop:spring.batch.job.enabled[] to `false`.
49-
50-
See {code-spring-boot-autoconfigure-src}/batch/BatchAutoConfiguration.java[`BatchAutoConfiguration`] for more details.
51-
52-
53-
5440
[[howto.batch.running-from-the-command-line]]
5541
== Running From the Command Line
5642

documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/io/index.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
Most applications will need to deal with input and output concerns at some point.
55
Spring Boot provides utilities and integrations with a range of technologies to help when you need IO capabilities.
6-
This section covers standard IO features such as caching and validation as well as more advanced topics such as scheduling and distributed transactions.
6+
This section covers standard IO features such as caching and validation as well as more advanced topics such as batch, scheduling, and distributed transactions.
77
We will also cover calling remote REST or SOAP services and sending email.
88

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[[io.spring-batch]]
2+
= Spring Batch
3+
4+
Spring Boot offers several conveniences for working with {url-spring-batch-site}[Spring Batch], including running a Job on startup.
5+
6+
If Spring Batch is available on your classpath, it is initialized through the javadoc:org.springframework.batch.core.configuration.annotation.EnableBatchProcessing[format=annotation] annotation.
7+
8+
When building a batch application, the following stores can be auto-configured:
9+
10+
* In-memory
11+
* JDBC
12+
13+
Each store has specific additional settings.
14+
For instance, it is possible to customize the tables prefix for the JDBC store, as shown in the following example:
15+
16+
[configprops,yaml]
17+
----
18+
spring:
19+
batch:
20+
jdbc:
21+
table-prefix: "CUSTOM_"
22+
----
23+
24+
You can take control over Spring Batch's configuration using javadoc:org.springframework.batch.core.configuration.annotation.EnableBatchProcessing[format=annotation].
25+
This will cause the auto-configuration to back off.
26+
Spring Batch can then be configured using the `@Enable*JobRepository` annotation's attributes rather than the previously described configuration properties.
27+
28+
29+
30+
[[io.spring-batch.running-jobs-on-startup]]
31+
== Running Spring Batch Jobs on Startup
32+
33+
When Spring Boot auto-configures Spring Batch, and if a single javadoc:org.springframework.batch.core.Job[] bean is found in the application context, it is executed on startup (see javadoc:org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner[] for details).
34+
If multiple javadoc:org.springframework.batch.core.Job[] beans are found, the job that should be executed must be specified using configprop:spring.batch.job.name[].
35+
36+
You can disable running a javadoc:org.springframework.batch.core.Job[] found in the application context, as shown in the following example:
37+
38+
[configprops,yaml]
39+
----
40+
spring:
41+
batch:
42+
job:
43+
enabled: false
44+
----
45+
46+
47+
See javadoc:org.springframework.boot.batch.autoconfigure.BatchAutoConfiguration[] and javadoc:org.springframework.boot.batch.jdbc.autoconfigure.BatchJdbcAutoConfiguration[] for more details.

documentation/spring-boot-docs/src/docs/antora/modules/reference/partials/nav-reference.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
** xref:reference:io/index.adoc[]
4141
*** xref:reference:io/caching.adoc[]
42+
*** xref:reference:io/spring-batch.adoc[]
4243
*** xref:reference:io/hazelcast.adoc[]
4344
*** xref:reference:io/quartz.adoc[]
4445
*** xref:reference:io/email.adoc[]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the License);
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
plugins {
18+
id "java-library"
19+
id "org.springframework.boot.auto-configuration"
20+
id "org.springframework.boot.configuration-properties"
21+
id "org.springframework.boot.deployed"
22+
id "org.springframework.boot.optional-dependencies"
23+
}
24+
25+
description = "Spring Boot Batch JDBC"
26+
27+
dependencies {
28+
api(project(":module:spring-boot-batch"))
29+
api(project(":module:spring-boot-jdbc"))
30+
31+
implementation(project(":module:spring-boot-tx"))
32+
33+
optional(project(":core:spring-boot-autoconfigure"))
34+
optional(project(":module:spring-boot-hibernate"))
35+
optional(project(":module:spring-boot-micrometer-observation"))
36+
37+
testImplementation(project(":core:spring-boot-test"))
38+
testImplementation(project(":module:spring-boot-flyway"))
39+
testImplementation(project(":module:spring-boot-liquibase"))
40+
testImplementation(project(":test-support:spring-boot-test-support"))
41+
testImplementation(testFixtures(project(":core:spring-boot-autoconfigure")))
42+
testImplementation("io.micrometer:micrometer-observation-test")
43+
44+
testRuntimeOnly("ch.qos.logback:logback-classic")
45+
testRuntimeOnly("com.fasterxml.jackson.core:jackson-databind")
46+
testRuntimeOnly("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
47+
testRuntimeOnly("com.h2database:h2")
48+
testRuntimeOnly("com.zaxxer:HikariCP")
49+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.batch.autoconfigure;
17+
package org.springframework.boot.batch.jdbc.autoconfigure;
1818

1919
import java.lang.annotation.Documented;
2020
import java.lang.annotation.ElementType;
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.batch.autoconfigure;
17+
package org.springframework.boot.batch.jdbc.autoconfigure;
1818

1919
import java.util.List;
2020

@@ -43,7 +43,7 @@ public class BatchDataSourceScriptDatabaseInitializer extends DataSourceScriptDa
4343
* @param properties the Spring Batch JDBC properties
4444
* @see #getSettings
4545
*/
46-
public BatchDataSourceScriptDatabaseInitializer(DataSource dataSource, BatchProperties.Jdbc properties) {
46+
public BatchDataSourceScriptDatabaseInitializer(DataSource dataSource, BatchJdbcProperties properties) {
4747
this(dataSource, getSettings(dataSource, properties));
4848
}
4949

@@ -58,24 +58,23 @@ public BatchDataSourceScriptDatabaseInitializer(DataSource dataSource, DatabaseI
5858
}
5959

6060
/**
61-
* Adapts {@link BatchProperties.Jdbc Spring Batch JDBC properties} to
62-
* {@link DatabaseInitializationSettings} replacing any {@literal @@platform@@}
63-
* placeholders.
61+
* Adapts {@link BatchJdbcProperties} to {@link DatabaseInitializationSettings}
62+
* replacing any {@literal @@platform@@} placeholders.
6463
* @param dataSource the Spring Batch data source
6564
* @param properties batch JDBC properties
6665
* @return a new {@link DatabaseInitializationSettings} instance
6766
* @see #BatchDataSourceScriptDatabaseInitializer(DataSource,
6867
* DatabaseInitializationSettings)
6968
*/
70-
public static DatabaseInitializationSettings getSettings(DataSource dataSource, BatchProperties.Jdbc properties) {
69+
public static DatabaseInitializationSettings getSettings(DataSource dataSource, BatchJdbcProperties properties) {
7170
DatabaseInitializationSettings settings = new DatabaseInitializationSettings();
7271
settings.setSchemaLocations(resolveSchemaLocations(dataSource, properties));
7372
settings.setMode(properties.getInitializeSchema());
7473
settings.setContinueOnError(true);
7574
return settings;
7675
}
7776

78-
private static List<String> resolveSchemaLocations(DataSource dataSource, BatchProperties.Jdbc properties) {
77+
private static List<String> resolveSchemaLocations(DataSource dataSource, BatchJdbcProperties properties) {
7978
PlatformPlaceholderDatabaseDriverResolver platformResolver = new PlatformPlaceholderDatabaseDriverResolver();
8079
if (StringUtils.hasText(properties.getPlatform())) {
8180
return platformResolver.resolveAll(properties.getPlatform(), properties.getSchema());

0 commit comments

Comments
 (0)