Skip to content

Commit e6d2082

Browse files
denisfalquetoclaude
andcommitted
Document the ApplicationPropertiesCustomizer extension point
Describe in the configuration guide how application properties can be contributed to the generated project, including how to target another source set or Spring profile through sections, with a runnable example. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Signed-off-by: Denis A. Altoé Falqueto <denisfalqueto@gmail.com>
1 parent 643ec18 commit e6d2082

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

‎initializr-docs/src/main/asciidoc/configuration-guide.adoc‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,21 @@ requires you to add a certain plugin to the build, you can provide a `BuildCusto
215215
that adds the plugin and the customizer will be called according to the order specified on
216216
it.
217217

218+
Similarly, an `ApplicationPropertiesCustomizer` can be used to contribute properties to
219+
the application configuration file of the generated project, that is
220+
`application.properties` or `application.yaml` depending on the requested
221+
`ConfigurationFileFormat`. Properties added directly to the `ApplicationProperties`
222+
argument are written to the configuration file of the main source set and the default
223+
profile. Properties for another source set or Spring profile can be added to the matching
224+
`section`, and a `src/{sourceSet}/resources/application[-{profile}].{properties|yaml}`
225+
file, resolved against the project's build system, is generated for every section that
226+
contains properties, as shown in the following example:
227+
228+
[source,java,indent=0]
229+
----
230+
include::{code-examples}/doc/generator/project/ProjectCustomizationExamples.java[tag=application-properties-customizer]
231+
----
232+
218233

219234

220235
[[initializr-generator-spring-requirements]]

‎initializr-docs/src/main/java/io/spring/initializr/doc/generator/project/ProjectCustomizationExamples.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import io.spring.initializr.generator.project.ProjectDescriptionCustomizer;
2626
import io.spring.initializr.generator.project.ProjectDescriptionField;
2727
import io.spring.initializr.generator.spring.build.BuildCustomizer;
28+
import io.spring.initializr.generator.spring.properties.ApplicationPropertiesCustomizer;
29+
import io.spring.initializr.generator.spring.properties.SourceSet;
2830

2931
import org.springframework.context.annotation.Bean;
3032

@@ -69,4 +71,18 @@ private boolean isBelowJava17(String jvmVersion) {
6971
}
7072
// end::jvm-version-change-reason[]
7173

74+
// tag::application-properties-customizer[]
75+
@Bean
76+
public ApplicationPropertiesCustomizer applicationPropertiesCustomizer() {
77+
return (properties) -> {
78+
// src/main/resources/application.properties (or .yaml)
79+
properties.add("spring.application.name", "acme");
80+
// src/test/resources/application.properties
81+
properties.section(SourceSet.TEST).add("spring.datasource.url", "jdbc:h2:mem:acme");
82+
// src/main/resources/application-dev.properties
83+
properties.section(SourceSet.MAIN, "dev").add("logging.level.root", "DEBUG");
84+
};
85+
}
86+
// end::application-properties-customizer[]
87+
7288
}

0 commit comments

Comments
 (0)