DEV Community

Devanshu Biswas
Devanshu Biswas

Posted on

OrderHub Day 7: Config & Profiles With @ConfigurationProperties (Spring Boot)

OrderHub Day 7: stop hard-coding values and start configuring them. Today the app gets type-safe configuration with @ConfigurationProperties and dev/prod profiles — one build that behaves correctly in every environment.

⚙️ Flip dev/prod + edit the config live: https://dev48v.infy.uk/orderhub/day7-config-profiles.html

Externalize the knobs

Magic numbers (max quantity, default page size) move out of the code and into application.yml:

app:
  orders:
    max-quantity: 1000
    default-page-size: 20
    max-page-size: 100
Enter fullscreen mode Exit fullscreen mode

Bind it type-safely

A @ConfigurationProperties(prefix = "app.orders") record binds those keys into a typed bean — far better than scattering @Value("${...}") strings around. The service injects it and uses maxQuantity / defaultPageSize instead of literals.

Profiles = one jar, many environments

application-dev.yml (verbose logging, SQL on, small page sizes) and application-prod.yml (quiet logging, env-driven datasource, larger limits) override the base. Spring picks one via SPRING_PROFILES_ACTIVE — Render sets prod, your laptop runs dev. Same artifact, different behavior, zero code changes.

The golden rule

Config precedence: environment > profile > base. And secrets live in env vars — never commit them.

🔨 Full walkthrough (@ConfigurationProperties → bind → profiles → SPRING_PROFILES_ACTIVE) on the page: https://dev48v.infy.uk/orderhub/day7-config-profiles.html

OrderHub — a production-grade Spring Boot backend, one feature a day.
🌐 https://dev48v.infy.uk · Code: https://github.com/dev48v/order-hub-from-zero

Top comments (0)