Skip to the page

Spring Boot core · mid

Auto-configuration and where properties come from

A starter brings dependencies. Auto-configuration creates beans only when conditions match. Property sources have an order, and a higher one wins.

The notes

What you must know

  • A starter is a bundle of dependencies. Each Boot module lists its auto-configuration classes, guarded by conditions: @ConditionalOnClass, @ConditionalOnMissingBean, @ConditionalOnProperty.
  • See the decisions with --debug (condition evaluation report) or the /actuator/conditions endpoint.
  • To change them, in this order: properties (spring.datasource.*, spring.jpa.*), your own bean, then @SpringBootApplication(exclude = ...).
  • Spring Boot 4 split auto-configuration into smaller modules with a starter per technology: Flyway needs spring-boot-starter-flyway, not just the Flyway library.
  • Property precedence, highest first (simplified): command-line arguments, OS environment variables (SPRING_DATASOURCE_URL maps to spring.datasource.url), profile files, then the default file.
  • Find the source of a value: /actuator/env lists each property and where it came from. Values are masked by default. Keep this endpoint internal and secured.
  • Incident: production wrote into the staging database because an environment variable copied from staging overrode application-prod.yml. Stop the writes first, then fix the source.
  • Prevent: one source of truth per environment for URLs and secrets (a secrets manager), separate credentials per environment so a staging password cannot reach production.

The red pen

Common traps: mistake → fix

  • Mistake: application-prod.yml always wins in production

    Fix: environment variables and command-line arguments override files.

  • Mistake: Adding a starter changes nothing until I add code

    Fix: auto-configuration creates beans by itself.

  • Mistake: Auto-configuration cannot be changed

    Fix: use properties, your own bean or exclude.

Easy to hard

Questions interviewers ask, easy to hard

  1. You add spring-boot-starter-data-jpa and get a DataSource. How does Spring Boot decide?
  2. How do you find out why a bean was or was not created?
  3. Which property source wins: the YAML file or an environment variable?
  4. After a release, production wrote to the staging database. What do you do?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview