The application.properties file is the default external configuration file of a Spring Boot application. It holds key-value settings such as the server port, database connection, logging levels and your own custom properties, so you can change behaviour without recompiling the code. Spring Boot loads it automatically from the classpath at startup and binds the values into the Environment.
You can write the same settings in application.yml instead, and you can override either file per environment with profiles, environment variables or command-line arguments.
Spring Boot looks for application.properties (or application.yml) in these locations, with later entries overriding earlier ones:
src/main/resources./config package on the classpath./config subdirectory of the working directory.Everything in the file becomes part of the Spring Environment. Spring Boot's auto-configuration then reads well-known keys (for example server.port or spring.datasource.url) to configure the embedded server, the connection pool, JPA and dozens of other components.
The ${DB_PASSWORD} placeholder is resolved from an environment variable, which keeps the secret out of the file.
| Area | Example keys | Purpose |
|---|---|---|
| Web server | server.port, server.servlet.context-path | Port and base path of the embedded server |
| Database | spring.datasource.url, spring.datasource.username | JDBC connection |
| JPA | spring.jpa.hibernate.ddl-auto, spring.jpa.show-sql | Schema handling and SQL logging |
| Logging | logging.level.*, logging.file.name | Log levels and files |
| Actuator | management.endpoints.web.exposure.include | Which monitoring endpoints are exposed |
| Profiles | spring.profiles.active | Which profile is active |
For schema management in production, prefer a migration tool such as Flyway or Liquibase and set spring.jpa.hibernate.ddl-auto=validate or none, instead of letting Hibernate change the schema.
A profile-specific file named application-{profile}.properties is loaded in addition to the base file, and its values win. Activate a profile with spring.profiles.active.
In production you normally do not hard-code the active profile. Pass it from outside instead:
Use @Value for a single value, or @ConfigurationProperties to bind a group of related keys to a typed object. The second approach is the recommended one for anything beyond a single value because it supports validation and IDE auto-completion.
Spring Boot binds the app.mail.* keys to the record's constructor. Relaxed binding means app.mail.sender, APP_MAIL_SENDER and app.mail.sender all map to the same property.
Spring Boot merges many property sources. From highest to lowest priority, the most useful ones are:
--server.port=9000.-Dserver.port=9000).SERVER_PORT=9000).application.properties outside the jar, then inside it.Because environment variables and command-line arguments win, one container image can run in every environment with different configuration.
Both formats configure the same keys. Properties files are flat, while YAML expresses hierarchy and lists more readably.
Pick one format per project to avoid confusion. If both files exist in the same location, the .properties file takes precedence over the .yml file.
Do not commit passwords, API keys or tokens. Use environment variables, a secrets manager, Kubernetes secrets or Spring Cloud Config, and keep only placeholders in the file. Also limit what Actuator exposes, since /env and /configprops can reveal configuration values.
Put it in src/main/resources. Maven and Gradle copy it to the classpath root of the built jar, where Spring Boot finds it.
Yes. Set spring.config.name=myconfig to change the base name, or spring.config.location or spring.config.import to load specific files.
The source with the higher precedence wins. Within one file, the last occurrence of a key is used.
No. Spring Boot runs with sensible defaults. You only add the file when you need to change them.
application.properties is the central, externalised configuration file of a Spring Boot application. Use it for server, database, logging and custom settings, add application-{profile}.properties for each environment, bind groups of keys with @ConfigurationProperties, and keep secrets in environment variables or a secrets store.