Bird
Raised Fist0
Spring Bootframework~10 mins

Configuration precedence order in Spring Boot - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Configuration precedence order
Default Properties
↓
application.properties/yml
↓
Profile-specific Properties
↓
Command Line Arguments
↓
Environment Variables
↓
@PropertySource Annotations
↓
Spring Boot Config Files in External Locations
↓
Final Resolved Property
Spring Boot loads configuration properties in a specific order, where later sources override earlier ones.
Execution Sample
Spring Boot
spring.application.name=defaultApp
spring.application.name=profileApp
spring.application.name=cliApp
Shows how the same property is overridden by profile and then command line arguments.
Execution Table
StepSourceProperty KeyValue LoadedOverride Previous?
1Default Propertiesspring.application.namedefaultAppNo
2application.propertiesspring.application.namedefaultAppNo (same value)
3Profile-specific Propertiesspring.application.nameprofileAppYes
4Command Line Argumentsspring.application.namecliAppYes
5Environment Variablesspring.application.namecliAppNo (same value)
6@PropertySource Annotationsspring.application.namecliAppNo (same value)
7External Config Filesspring.application.namecliAppNo (same value)
8Final Resolved Propertyspring.application.namecliAppFinal value after all overrides
💡 All sources checked; final property value is from command line arguments.
Variable Tracker
PropertyDefaultapplication.propertiesProfile-specificCommand LineEnvironmentPropertySourceExternalFinal
spring.application.namedefaultAppdefaultAppprofileAppcliAppcliAppcliAppcliAppcliApp
Key Moments - 2 Insights
Why does the command line argument override profile-specific properties?
Because in the execution_table, step 4 shows command line arguments loaded after profile-specific properties (step 3), so it takes precedence.
If environment variables have the same property, do they always override command line arguments?
No, as shown in step 5, environment variables load after command line arguments but do not override if the value is the same.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does the property value change from 'profileApp' to 'cliApp'?
AStep 4
BStep 3
CStep 5
DStep 2
💡 Hint
Check the 'Value Loaded' and 'Override Previous?' columns in execution_table rows 3 and 4.
According to variable_tracker, what is the final value of 'spring.application.name'?
AdefaultApp
BprofileApp
CcliApp
DenvironmentApp
💡 Hint
Look at the 'Final' column for 'spring.application.name' in variable_tracker.
If you remove the command line argument, which source provides the final property value?
AEnvironment Variables
BProfile-specific Properties
CDefault Properties
Dapplication.properties
💡 Hint
Refer to the order in concept_flow and execution_table where command line arguments override profile-specific properties.
Concept Snapshot
Spring Boot loads configuration properties in this order:
1. Default properties
2. application.properties or .yml
3. Profile-specific properties
4. Command line arguments
5. Environment variables
6. @PropertySource annotations
7. External config files
Later sources override earlier ones.
Full Transcript
Spring Boot reads configuration properties from multiple sources in a specific order. It starts with default properties, then loads application.properties or application.yml files. Next, it loads profile-specific properties that override previous values. Command line arguments come after and override profile properties. Environment variables and @PropertySource annotations are loaded later, followed by external configuration files. The final property value is the one from the highest precedence source. This order ensures flexible configuration management where you can override settings easily for different environments or runtime needs.

Practice

(1/5)
1. In Spring Boot, which configuration source has the highest priority and overrides all others?
easy
A. Environment variables
B. Command line arguments
C. application.properties file
D. Default properties in code

Solution

  1. Step 1: Understand configuration sources in Spring Boot

    Spring Boot loads configuration from multiple sources like properties files, environment variables, and command line arguments.
  2. Step 2: Identify the highest priority source

    Command line arguments have the highest priority and override all other configuration sources.
  3. Final Answer:

    Command line arguments -> Option B
  4. Quick Check:

    Highest priority = Command line arguments [OK]
Hint: Remember: command line args always override others [OK]
Common Mistakes:
  • Thinking application.properties has highest priority
  • Confusing environment variables with command line args
  • Assuming default properties override others
2. Which of the following is the correct way to specify a property in Spring Boot's application.properties file?
easy
A. server.port=8080
B. server-port:8080
C. server_port=8080
D. serverPort=8080

Solution

  1. Step 1: Recall Spring Boot property syntax

    Spring Boot uses dot notation in application.properties files, like server.port=8080.
  2. Step 2: Check each option's syntax

    server.port=8080 uses correct dot notation. Options B, C, and D use invalid separators or camelCase which are not valid in properties files.
  3. Final Answer:

    server.port=8080 -> Option A
  4. Quick Check:

    Properties use dot notation = server.port=8080 [OK]
Hint: Use dot notation for properties in application.properties [OK]
Common Mistakes:
  • Using underscores instead of dots
  • Using colon instead of equals sign
  • Using camelCase instead of dot notation
3. Given the following Spring Boot configuration sources:
application.properties sets server.port=8080
Environment variable SERVER_PORT=9090
Command line argument --server.port=7070
What port will the application run on?
medium
A. 7070
B. 9090
C. Default port 8081
D. 8080

Solution

  1. Step 1: List configuration sources and their values

    application.properties: 8080, environment variable: 9090, command line argument: 7070.
  2. Step 2: Apply Spring Boot precedence order

    Command line arguments override environment variables and properties files, so port is 7070.
  3. Final Answer:

    7070 -> Option A
  4. Quick Check:

    Command line args override others = 7070 [OK]
Hint: Command line args always win over env and properties [OK]
Common Mistakes:
  • Choosing environment variable value instead of command line
  • Assuming properties file overrides environment variables
  • Forgetting default port fallback
4. You set server.port=8080 in application.properties and also pass --server.port=9090 as a command line argument, but the app still runs on port 8080. What is the most likely cause?
medium
A. application.properties has higher priority
B. Spring Boot ignores command line arguments by default
C. Environment variable overrides command line
D. Command line argument syntax is incorrect

Solution

  1. Step 1: Understand expected behavior

    Command line arguments should override properties file settings.
  2. Step 2: Identify why command line arg might be ignored

    If the syntax is wrong (e.g., missing dashes or wrong format), Spring Boot won't apply it.
  3. Final Answer:

    Command line argument syntax is incorrect -> Option D
  4. Quick Check:

    Incorrect syntax means command line ignored [OK]
Hint: Check command line argument format carefully [OK]
Common Mistakes:
  • Assuming properties file always overrides command line
  • Thinking environment variables override command line
  • Believing Spring Boot ignores command line args by default
5. You want to set a default property app.mode=dev in your Spring Boot app but allow it to be overridden by environment variables or command line arguments. Which order of precedence correctly applies?
hard
A. Environment variables < Command line arguments < application.properties < Default properties
B. Command line arguments < Environment variables < application.properties < Default properties
C. Default properties < application.properties < Environment variables < Command line arguments
D. application.properties < Default properties < Command line arguments < Environment variables

Solution

  1. Step 1: Understand default property placement

    Default properties are lowest priority and can be overridden by all other sources.
  2. Step 2: Recall Spring Boot precedence order

    Order is: Default properties < application.properties < Environment variables < Command line arguments.
  3. Final Answer:

    Default properties < application.properties < Environment variables < Command line arguments -> Option C
  4. Quick Check:

    Lowest to highest priority = Default properties < application.properties < Environment variables < Command line arguments [OK]
Hint: Remember: default < properties < env vars < command line [OK]
Common Mistakes:
  • Mixing order of environment variables and properties file
  • Placing default properties above application.properties
  • Reversing command line argument priority
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard