The application-{profile}.properties file holds configuration that Spring Boot loads only when the named profile is active. For example, application-prod.properties is read when the prod profile is active, and its values override the same keys in the base application.properties. This lets one build run unchanged in development, test and production with different databases, ports and log levels.
Profile files are part of Spring Boot's externalized configuration. The base file always loads first, and each active profile file layers on top of it, so you only repeat the values that differ.
The file name follows the pattern application-{profile}.properties, where {profile} is any profile name you choose, such as dev, test or prod. Spring Boot looks for these files in the same locations as the default file: the classpath root, a /config folder on the classpath, the current directory, and a /config subdirectory of the current directory.
The same naming works for YAML: application-prod.yml or application-prod.yaml. If both .properties and .yml exist for the same profile, the .properties file wins.
A profile file is ignored until the profile is active. You can activate profiles in several ways, listed here from the lowest to the highest precedence for most setups:
application.properties: spring.profiles.active=dev.SPRING_PROFILES_ACTIVE=prod.-Dspring.profiles.active=prod.--spring.profiles.active=prod.You can activate several profiles at once with a comma-separated list, for example --spring.profiles.active=prod,metrics. When the same key appears in more than one active profile file, the profile listed last wins. If no profile is active, Spring Boot activates the default profile and also loads application-default.properties when it exists.
The base file holds values shared by every environment.
Each profile file overrides or adds only what changes.
With prod active, server.port is 80 and logging.level.root stays INFO from the base file. Credentials come from environment variables, so they never live in the repository.
Profiles also control which beans exist. You can combine a profile file with @Profile so that environment-specific code and environment-specific settings switch together.
To read a value in a bean, use @Value("${server.port}") or, preferably, a type-safe @ConfigurationProperties class. Both read the merged result of the base file and the active profile files.
Since Spring Boot 2.4 you can group profiles so one name activates several others.
Activating production then activates prod, metrics and audit, each with its own application-<name>.properties. You can also keep several profiles in a single file. In .properties files, separate documents with #--- and use spring.config.activate.on-profile inside each one. Note that spring.profiles (the old key) was replaced by spring.config.activate.on-profile in Boot 2.4, and spring.profiles.active cannot be set inside a profile-specific document.
Overall precedence, from lowest to highest, is: the packaged default file, packaged profile files, then files outside the jar, followed by environment variables, system properties and command-line arguments. A value passed on the command line always beats any file.
application.properties and put only differences in profile files.spring.profiles.active in a committed base file for production; set it in the deployment environment instead./actuator/env endpoint, if Actuator is enabled and secured.Nothing fails. Spring Boot treats a missing profile file as optional and simply uses the base configuration and any other active profiles.
application-dev.properties and application-dev.yml?You can, but avoid it. If both define the same key, the .properties file takes precedence, which makes the result confusing.
Annotate the test class with @ActiveProfiles("test"). Spring then loads application-test.properties on top of the base file for that test context.
No. Command-line arguments, system properties and environment variables have higher precedence than any file.
The application-{profile}.properties file stores environment-specific settings that apply only when its profile is active. It overrides the base application.properties, keeps one artifact deployable everywhere, and works together with @Profile, profile groups and @ActiveProfiles. Keep secrets out of the files and set the active profile in the runtime environment.