From 4f875ad39bdb9c958845eaea03a926987615a687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Tue, 29 Jul 2025 09:18:18 +0200 Subject: [PATCH] Rely on configuration properties annotation processor This commit switches from manual metadata to using the configuration properties annotation processor like other modules do. This reduces the amount of manual metadata, document missing properties and prevent inconsistencies going forward. Closes gh-46584 --- .../build.gradle | 11 +----- .../SpringBootMockMvcBuilderCustomizer.java | 9 +++++ ...itional-spring-configuration-metadata.json | 16 +++++++++ .../spring-configuration-metadata.json | 34 ------------------- 4 files changed, 26 insertions(+), 44 deletions(-) create mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json delete mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring-configuration-metadata.json diff --git a/spring-boot-project/spring-boot-test-autoconfigure/build.gradle b/spring-boot-project/spring-boot-test-autoconfigure/build.gradle index 188a4a888e2..61833c35ef3 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/build.gradle +++ b/spring-boot-project/spring-boot-test-autoconfigure/build.gradle @@ -16,6 +16,7 @@ plugins { id "java-library" + id "org.springframework.boot.configuration-properties" id "org.springframework.boot.deployed" id "org.springframework.boot.docker-test" id "org.springframework.boot.optional-dependencies" @@ -146,16 +147,6 @@ dependencies { testImplementation("org.thymeleaf:thymeleaf") } -configurations { - configurationPropertiesMetadata -} - -artifacts { - configurationPropertiesMetadata new File(sourceSets.main.output.resourcesDir, "META-INF/spring-configuration-metadata.json"), { artifact -> - artifact.builtBy sourceSets.main.processResourcesTaskName - } -} - test { include "**/*Tests.class" } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/SpringBootMockMvcBuilderCustomizer.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/SpringBootMockMvcBuilderCustomizer.java index e696698fa91..fee3dbac76a 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/SpringBootMockMvcBuilderCustomizer.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/SpringBootMockMvcBuilderCustomizer.java @@ -59,10 +59,19 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi private final WebApplicationContext context; + /** + * Whether to add servlet filters. + */ private boolean addFilters = true; + /** + * MVC Print option. + */ private MockMvcPrint print = MockMvcPrint.DEFAULT; + /** + * Whether to only print failed exchanges. + */ private boolean printOnlyOnFailure = true; /** diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json new file mode 100644 index 00000000000..a159ff61347 --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -0,0 +1,16 @@ +{ + "properties": [ + { + "name": "spring.test.database.replace", + "type": "org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase$Replace", + "description": "Type of existing DataSource to replace.", + "defaultValue": "any" + }, + { + "name": "spring.test.observability.auto-configure", + "type": "java.lang.Boolean", + "description": "Whether observability should be auto-configured in tests.", + "defaultValue": false + } + ] +} diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring-configuration-metadata.json b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring-configuration-metadata.json deleted file mode 100644 index 26173fdc4a5..00000000000 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring-configuration-metadata.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "properties": [ - { - "name": "spring.test.database.replace", - "type": "org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase$Replace", - "description": "Type of existing DataSource to replace.", - "defaultValue": "any" - }, - { - "name": "spring.test.mockmvc.add-filters", - "type": "java.lang.Boolean", - "description": "Whether to add servlet filters.", - "defaultValue": true - }, - { - "name": "spring.test.mockmvc.print", - "type": "org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrint", - "description": "MVC Print option.", - "defaultValue": "default" - }, - { - "name": "spring.test.mockmvc.print-only-on-failure", - "type": "java.lang.Boolean", - "description": "Whether to only print failed exchanges.", - "defaultValue": true - }, - { - "name": "spring.test.observability.auto-configure", - "type": "java.lang.Boolean", - "description": "Whether observability should be auto-configured in tests.", - "defaultValue": false - } - ] -}