METABYTE
Back to articles

Spring Boot Configuration Priority: A Tiny Detail That Wastes Hours

Understanding Spring Boot's config priority order saves you from debugging hell and late nights.

12 mai 20262 min read
Spring Boot Configuration Priority: A Tiny Detail That Wastes Hours

Ever changed a property in application.yml, fired up your app, and watched it completely ignore your change? Welcome to the club. Spring Boot has a strict hierarchy of configuration sources, and not knowing it is a one-way ticket to debugging purgatory.

How It Works (and Backfires)

Spring Boot applies settings in a precise order: higher priority wins. The hierarchy from highest to lowest:

  1. Command-line arguments (e.g., --server.port=9090)
  2. JNDI attributes (archaic but present)
  3. JVM system properties (via -D)
  4. OS environment variables (DevOps' favorite)
  5. application-{profile}.properties/yml (profile-specific)
  6. application.properties/yml (the default)
  7. @PropertySource on config classes (if you're into that)
  8. Default values (via @Value with defaults)

Classic pain point: you tweak application.yml, but SERVER_PORT env var is set on the server — your app stubbornly listens on 8080 instead of 9090. Or a colleague passed a command-line arg in Docker, and you spend half a day hunting down the rogue value.

Where the Trap Lies

The real killer is forgetting about higher-priority sources. Environment variables are especially sneaky — they can be set by the system, CI/CD, or just linger in a terminal session. Another gotcha: profiles. If you launch with spring.profiles.active=prod, application-prod.yml overrides common settings but still bows to command-line args.

How to Keep Your Sanity

  • Always check active sources via Actuator: /actuator/env shows all values and their origin.
  • Use prefixes like --spring.config.additional-location to explicitly point to files.
  • Don't rely on magic: if behavior seems off, start by checking environment variables and launch arguments.

METABYTE studio comment: We've all been there — your app ignoring config like a teenager ignoring chores. Our devs always double-check the priority chain so you don't lose sleep over a phantom server.port. And if you want to automate config management, we can make that painless too.

NEXT STEP

Liked the approach?

We apply the same principles to client projects: AI, automation, products that don't die after launch.