Skip to content

Commit f584d6d

Browse files
committed
Replace @EnableBatchProcessing in slice test examples
Using `@EnableBatchProcessing` is no longer necessary to enable Batch's auto-configuration so it's no longer a good example when discussing sliced tests and user configuration. This commit replaces `@EnableBatchProcessing` with an alternative annotation, `@EnableMongoAuditing` and updates the accompanying text. Closes gh-33435
1 parent 35ee522 commit f584d6d

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/testing.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -855,15 +855,15 @@ If you <<using#using.structuring-your-code, structure your code>> in a sensible
855855

856856
It then becomes important not to litter the application's main class with configuration settings that are specific to a particular area of its functionality.
857857

858-
Assume that you are using Spring Batch and you rely on the auto-configuration for it.
858+
Assume that you are using Spring Data MongoDB, you rely on the auto-configuration for it, and you have enabled auditing.
859859
You could define your `@SpringBootApplication` as follows:
860860

861861
include::code:MyApplication[]
862862

863-
Because this class is the source configuration for the test, any slice test actually tries to start Spring Batch, which is definitely not what you want to do.
863+
Because this class is the source configuration for the test, any slice test actually tries to enable Mongo auditing, which is definitely not what you want to do.
864864
A recommended approach is to move that area-specific configuration to a separate `@Configuration` class at the same level as your application, as shown in the following example:
865865

866-
include::code:MyBatchConfiguration[]
866+
include::code:MyMongoConfiguration[]
867867

868868
NOTE: Depending on the complexity of your application, you may either have a single `@Configuration` class for your customizations or one class per domain area.
869869
The latter approach lets you enable it in one of your tests, if necessary, with the `@Import` annotation.

spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/testing/springbootapplications/userconfigurationandslicing/MyApplication.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,11 +16,11 @@
1616

1717
package org.springframework.boot.docs.features.testing.springbootapplications.userconfigurationandslicing;
1818

19-
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
2019
import org.springframework.boot.autoconfigure.SpringBootApplication;
20+
import org.springframework.data.mongodb.config.EnableMongoAuditing;
2121

2222
@SpringBootApplication
23-
@EnableBatchProcessing
23+
@EnableMongoAuditing
2424
public class MyApplication {
2525

2626
// ...
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,12 +16,12 @@
1616

1717
package org.springframework.boot.docs.features.testing.springbootapplications.userconfigurationandslicing;
1818

19-
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
2019
import org.springframework.context.annotation.Configuration;
20+
import org.springframework.data.mongodb.config.EnableMongoAuditing;
2121

2222
@Configuration(proxyBeanMethods = false)
23-
@EnableBatchProcessing
24-
public class MyBatchConfiguration {
23+
@EnableMongoAuditing
24+
public class MyMongoConfiguration {
2525

2626
// ...
2727

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/testing/springbootapplications/userconfigurationandslicing/MyApplication.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,11 +16,11 @@
1616

1717
package org.springframework.boot.docs.features.testing.springbootapplications.userconfigurationandslicing
1818

19-
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing
2019
import org.springframework.boot.autoconfigure.SpringBootApplication
20+
import org.springframework.data.mongodb.config.EnableMongoAuditing
2121

2222
@SpringBootApplication
23-
@EnableBatchProcessing
23+
@EnableMongoAuditing
2424
class MyApplication {
2525

2626
// ...
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,12 +16,12 @@
1616

1717
package org.springframework.boot.docs.features.testing.springbootapplications.userconfigurationandslicing
1818

19-
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing
2019
import org.springframework.context.annotation.Configuration
20+
import org.springframework.data.mongodb.config.EnableMongoAuditing;
2121

2222
@Configuration(proxyBeanMethods = false)
23-
@EnableBatchProcessing
24-
class MyBatchConfiguration {
23+
@EnableMongoAuditing
24+
class MyMongoConfiguration {
2525

2626
// ...
2727

0 commit comments

Comments
 (0)