Ardrey 情報マガジン

applicationproperties

📅 November 7, 2026📖 Verified Publication
```html application.properties Guide: Configuration Best Practices for Spring Boot

application.properties: The Complete Developer's Guide to Spring Boot Configuration

A single file can make or break your Spring Boot application. Master application.properties — from essential settings to advanced environment profiles — with this definitive guide.

Key Takeaways

  • Location matters: application.properties lives in src/main/resources/ and is auto-detected by Spring Boot on startup.
  • It overrides defaults: Every property you define here overrides Spring Boot's auto-configured defaults.
  • Use environment profiles: Leverage application-dev.properties, application-prod.properties, etc., for clean separation across environments.
  • Externalize secrets: Never commit passwords, API keys, or tokens — use Spring Cloud Config, Vault, or environment variables instead.
  • Properties order is irrelevant: Spring Boot resolves all properties after the file is loaded; ordering has no effect.
  • .properties vs YAML: Both are fully interchangeable — choose based on team convention and configuration depth.

What Is application.properties?

Definition and Purpose

application.properties is the default external configuration file for Spring Boot applications. It is a standard Java properties file that allows developers to override auto-configured defaults, wire in custom settings, and control every aspect of the application lifecycle — from server ports to datasource URLs, logging levels to feature flags.

Spring Boot automatically loads this file from the classpath (typically src/main/resources/application.properties) during bootstrap. You can also place it in platform-specific locations such as the current directory, a /config/ subdirectory, or the classpath root — each with a defined precedence order.

How Spring Boot Finds It

Spring Boot searches for application.properties (and its YAML counterpart application.yml) in the following order, from highest to lowest priority:

  1. Current working directory (root and /config/ subdirectory)
  2. classpath:/ (i.e., src/main/resources/)
  3. classpath:/config/
  4. Package JAR internals

Highest-priority sources override lower ones, enabling safe local overrides without touching source code.

Essential application.properties You Should Know

Server Configuration

Property Default Value What It Controls
server.port 8080 The HTTP port the application listens on
server.servlet.context-path / The base URL path for all endpoints
server.error.include-message never Whether error responses include a message field
server.compression.enabled false Toggles HTTP response compression
server.servlet.session.timeout 30m HTTP session expiration time

Data Source & Database

Property Example Value What It Controls
spring.datasource.url jdbc:postgresql://localhost:5432/mydb JDBC connection URL
spring.datasource.username postgres Database username
spring.datasource.password secret Database password
spring.datasource.driver-class-name org.postgresql.Driver JDBC driver class
spring.jpa.hibernate.ddl-auto update Schema generation strategy (validate, update, create, create-drop)
spring.jpa.show-sql true Prints generated SQL to the console
spring.sql.init.mode always Controls when data.sql / schema.sql are executed

Application & Metadata

Property Example Value What It Controls
spring.application.name my-service Application name used by Discovery, Config Server, and Actuator
spring.profiles.active dev Activates a specific profile at startup
logging.level.root INFO Root logger level
logging.level.org.springframework DEBUG Per-package logging verbosity
management.endpoints.web.exposure.include health,info,env,metrics Which Actuator endpoints are exposed over HTTP

application.properties vs application.yml: Which Should You Use?

This is one of the most common debates in the Spring Boot community. The answer is straightforward: both are functionally identical. Spring Boot treats them as interchangeable configuration formats with zero difference in resolution behavior.

Comparison at a Glance

© 2026 Ardrey 情報マガジン. All rights reserved.