Spring Boot’s externalized configuration system lets you supply properties through command-line arguments, environment variables,Documentation Index
Fetch the complete documentation index at: https://mintlify.com/spring-projects/spring-boot/llms.txt
Use this file to discover all available pages before exploring further.
application.properties, YAML files, and more — all merged in a well-defined precedence order. This guide answers the most common how-to questions around reading and customizing that configuration.
How do I set properties at startup?
How do I set properties at startup?
To set a property at startup, pass it as a command-line argument prefixed with Command-line arguments always override file-based property sources. To disable this behavior, call To set a property inside The same in YAML:
--:SpringApplication.setAddCommandLineProperties(false).To set properties via environment variables, replace dots with underscores and uppercase the name. For example, server.port becomes SERVER_PORT.To supply multiple properties as a single JSON blob, use SPRING_APPLICATION_JSON:application.properties so it applies by default:How do I load properties from a custom location?
How do I load properties from a custom location?
To replace the default config file search with a specific file or directory, set To add locations on top of the defaults rather than replacing them, use Properties from additional locations override those in the default locations, so you can keep shared defaults in the jar and override them at runtime with an external file.To rename the config file from To import additional files from inside
spring.config.location before the application starts (as a system property, environment variable, or command-line argument — not inside application.properties):spring.config.additional-location:application to something else:application.properties:How do I use YAML instead of .properties?
How do I use YAML instead of .properties?
To use YAML, create is equivalent to this YAML also supports multi-document files, which lets you activate sections per profile:
application.yaml (or application.yml) at the root of your classpath. Spring Boot loads YAML automatically when SnakeYAML is on the classpath — it is included transitively by spring-boot-starter.YAML maps directly to flat property names. The following YAML:application.properties:YAML files cannot be loaded with
@PropertySource or @TestPropertySource. If you need to load values that way, use a .properties file instead.How do I encrypt sensitive properties?
How do I encrypt sensitive properties?
Spring Boot does not include built-in property encryption, but it exposes Register the implementation in For a production-grade solution, Spring Cloud Vault stores externalized configuration in HashiCorp Vault and integrates with Spring Boot’s
EnvironmentPostProcessor as the integration point. Implement this interface to decrypt values before the application context starts:META-INF/spring.factories:Environment abstraction.When should I use @ConfigurationProperties vs @Value?
When should I use @ConfigurationProperties vs @Value?
Use Enable it on your main class or any Use Key differences:
@ConfigurationProperties when you have a group of related properties or hierarchical data. It provides relaxed binding, IDE metadata support, and type-safe structured objects:@Configuration class:@Value for simple, single-value injection where SpEL expressions are needed:| Feature | @ConfigurationProperties | @Value |
|---|---|---|
| Relaxed binding | Yes | Limited |
| IDE metadata support | Yes | No |
| SpEL evaluation | No | Yes |
What are relaxed binding rules?
What are relaxed binding rules?
Spring Boot accepts multiple naming formats for the same property when binding to
To convert a property name to an environment variable name:
@ConfigurationProperties beans. For a property firstName on a class with prefix my.main-project.person, all of the following are equivalent:| Property name | Format |
|---|---|
my.main-project.person.first-name | Kebab case (recommended for files) |
my.main-project.person.firstName | Camel case |
my.main-project.person.first_name | Underscore notation |
MY_MAINPROJECT_PERSON_FIRSTNAME | Upper case (recommended for env vars) |
- Replace dots (
.) with underscores (_). - Remove any dashes (
-). - Convert to uppercase.
spring.main.log-startup-info becomes SPRING_MAIN_LOGSTARTUPINFO.Relaxed binding applies to
@ConfigurationProperties only. @Value supports a limited subset of this behavior. Always use kebab-case canonical form in @Value annotations (e.g., @Value("${demo.item-price}")) to get the broadest matching.How do I convert Duration and DataSize properties?
How do I convert Duration and DataSize properties?
To express a Supported duration units: Supported data size units:
Duration property, Spring Boot accepts three formats:ns, us, ms, s, m, h, d. The default unit is milliseconds unless you annotate the field with @DurationUnit.To express a DataSize property:B, KB, MB, GB, TB. The default unit is bytes unless you annotate the field with @DataSizeUnit.Use these types in your @ConfigurationProperties class:How do I validate @ConfigurationProperties with Bean Validation?
How do I validate @ConfigurationProperties with Bean Validation?
To validate configuration properties at startup, annotate the class with Ensure a JSR-303 implementation is on the classpath (Hibernate Validator is included transitively by If a constraint is violated, the application fails fast at startup with a clear error message rather than failing later at runtime.
@Validated and add JSR-303 constraint annotations to its fields:spring-boot-starter-validation):Annotate nested properties classes with
@Valid to cascade validation into them. Without @Valid, only the top-level fields are checked.How do I automatically expand Maven or Gradle project properties?
How do I automatically expand Maven or Gradle project properties?
To embed build metadata (version, encoding, etc.) into your configuration files, use resource filtering.Maven: If you use Without the starter parent, add this to your Gradle: Configure the Then reference them in your config:
spring-boot-starter-parent, reference Maven properties with @..@ placeholders:pom.xml:processResources task to expand project properties: