0Pricing
Spring Boot 4 Microservices & REST APIs · Lesson

application.properties and YAML

Configure apps with properties and YAML files.

application.properties and YAML is a free Spring Boot 4 Microservices & REST APIs lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Spring Boot 4 Microservices & REST APIs learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Where Configuration Lives

Spring Boot reads externalized configuration from application.properties or application.yml, placed under src/main/resources. This keeps tunable values out of your compiled code.

At startup Boot loads these files into the Environment, making every key available for injection, conditional beans, and auto-configuration.

  • One file for the whole app, or split per profile
  • Values can be overridden later by env vars or CLI args

The .properties Format

The classic format is a flat list of key=value lines. Nested concepts are expressed with dotted keys.

It is simple and diff-friendly, but verbose when you have deep structures because each key repeats the full path.

server.port=8080
server.servlet.context-path=/api
spring.datasource.url=jdbc:postgresql://localhost:5432/app
spring.datasource.username=app_user
spring.jpa.hibernate.ddl-auto=validate

The YAML Format

application.yml expresses the same data as a hierarchy, so shared prefixes are written once. It is easier to read for deeply nested config like spring.jpa.properties.hibernate.*.

Indentation is significant: use spaces, never tabs, and keep two spaces per level.

server:
  port: 8080
  servlet:
    context-path: /api
spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/app
    username: app_user
  jpa:
    hibernate:
      ddl-auto: validate

Lists and Maps in YAML

YAML shines for collections. A sequence uses - items; a map is just nested keys. Spring binds these directly to List and Map properties.

app:
  cors:
    allowed-origins:
      - https://app.example.com
      - https://admin.example.com
  feature-flags:
    beta-search: true
    dark-mode: false

Referencing Other Properties

You can interpolate one property into another with ${...}. This avoids repeating literals and lets a single base value drive several derived keys.

app:
  name: orders-service
  base-url: https://api.example.com
  health-url: ${app.base-url}/actuator/health
logging:
  file:
    name: /var/log/${app.name}.log

Default Values with Placeholders

Inside a placeholder you can supply a fallback after a colon: ${KEY:default}. Spring uses the default when the referenced property or environment variable is absent.

app:
  timeout-ms: ${REQUEST_TIMEOUT:5000}
  region: ${AWS_REGION:eu-central-1}

Injecting Single Values with @Value

For one-off properties, inject directly with @Value. SpEL placeholders resolve against the Environment at bean creation time.

Use @Value for a handful of keys; prefer @ConfigurationProperties when a feature has many related settings.

@Service
public class OrderService {
    @Value("${app.timeout-ms:5000}")
    private long timeoutMs;

    @Value("${app.name}")
    private String appName;
}

Properties vs YAML: Trade-offs

Functionally they are interchangeable; the choice is about ergonomics.

  • .properties — trivial parsing, great for small/flat config, no indentation traps
  • .yml — concise for nested trees, native lists/maps, but indentation-sensitive

If both files exist, .properties takes precedence over .yml for the same key, which can surprise teams. Pick one convention.

Multiple Documents in One YAML

A single YAML file can hold several documents separated by ---. Combined with spring.config.activate.on-profile, this lets you keep common and profile-specific values together.

spring:
  application:
    name: orders
---
spring:
  config:
    activate:
      on-profile: dev
  datasource:
    url: jdbc:h2:mem:devdb

Type Conversion and Durations

Spring converts string values into rich types. Duration accepts suffixes like 30s or 5m, and DataSize accepts 10MB. Enums and List are also converted automatically.

app:
  cache-ttl: 30m
  max-upload: 10MB
  log-level: WARN

Where Not to Put Secrets

Checked-in application.yml is the wrong home for passwords and API keys. Keep secrets in environment variables, a vault, or a secrets manager, and reference them via placeholders.

  • Commit non-sensitive defaults only
  • Inject secrets at deploy time

Quick Check

Test your understanding of property precedence.

Recap

You learned how Spring Boot externalizes configuration.

  • application.properties and application.yml both feed the Environment
  • YAML is concise for nested trees and native lists/maps
  • Use ${...} for references and ${KEY:default} for fallbacks
  • Spring converts to types like Duration and DataSize
  • Keep secrets out of committed files

Frequently asked questions

Is the “application.properties and YAML” lesson free?

Yes — the full text of “application.properties and YAML” is free to read here on the web, and the Spring Boot 4 Microservices & REST APIs course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Spring Boot 4 Microservices & REST APIs course, upgrade to CoddyKit PRO.

What will I learn in “application.properties and YAML”?

Configure apps with properties and YAML files. You practise Spring Boot 4 Microservices & REST APIs with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Spring Boot 4 Microservices & REST APIs?

No prior experience is required. Spring Boot 4 Microservices & REST APIs on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “application.properties and YAML” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Spring Boot 4 Microservices & REST APIs lesson?

Yes. Every Spring Boot 4 Microservices & REST APIs lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. application.properties and YAML
  2. Profiles for Environments
  3. Type-Safe Configuration with @ConfigurationProperties
  4. Externalized and Override Configuration
← Back to Spring Boot 4 Microservices & REST APIs