Bird
Raised Fist0
Spring Bootframework~10 mins

application.yml alternative in Spring Boot - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - application.yml alternative
Start Spring Boot App
↓
Check for application.yml
No↓
Check for application.properties
Yes↓
Load properties from application.properties
↓
Use loaded properties in app
↓
Run
Spring Boot first looks for application.yml. If not found, it checks for application.properties and loads it to configure the app.
Execution Sample
Spring Boot
server.port=8081
spring.datasource.url=jdbc:mysql://localhost:3306/db
logging.level.root=INFO
This application.properties file sets server port, database URL, and logging level as an alternative to application.yml.
Execution Table
StepFile CheckedFound?ActionResult
1application.ymlNoSkip to next config fileNo YAML config loaded
2application.propertiesYesLoad propertiesProperties loaded into environment
3Use propertiesN/AConfigure app with loaded propertiesServer port=8081, DB URL set, Logging=INFO
4Start appN/ARun with configured settingsApp runs on port 8081 with given configs
💡 application.yml not found, application.properties found and loaded, app configured and started
Variable Tracker
VariableStartAfter Step 2After Step 3Final
server.portdefault 8080808180818081
spring.datasource.urlnonejdbc:mysql://localhost:3306/dbjdbc:mysql://localhost:3306/dbjdbc:mysql://localhost:3306/db
logging.level.rootdefault INFOINFOINFOINFO
Key Moments - 2 Insights
Why does Spring Boot use application.properties when application.yml is missing?
Spring Boot checks for application.yml first. If it doesn't find it (see execution_table step 1), it looks for application.properties and loads it instead (step 2).
Can I use application.properties and application.yml together?
Yes, but application.yml has higher priority. If both exist, Spring Boot loads application.yml first and overrides properties from application.properties.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does Spring Boot load the alternative config file?
AStep 3
BStep 1
CStep 2
DStep 4
💡 Hint
Check the 'Action' column for when properties are loaded.
According to variable_tracker, what is the final value of server.port?
A8080
B8081
Cdefault
Dnone
💡 Hint
Look at the 'Final' column for server.port.
If application.yml existed, how would the execution_table change?
AStep 1 would find application.yml and load it, skipping application.properties
BStep 2 would still load application.properties
CBoth files would load simultaneously
DApp would fail to start
💡 Hint
Refer to concept_flow showing priority order.
Concept Snapshot
Spring Boot config files order:
1. application.yml (preferred)
2. application.properties (alternative)
If application.yml missing, properties file loads.
Properties set here configure app behavior like port, DB, logging.
Use either file format but YAML has priority.
Full Transcript
Spring Boot applications look for configuration files to set up app settings. The preferred file is application.yml. If this file is missing, Spring Boot checks for application.properties as an alternative. When application.properties is found, Spring Boot loads its key-value pairs to configure the app, such as server port, database connection, and logging levels. This process ensures the app runs with the desired settings. If both files exist, application.yml takes priority and overrides properties from application.properties. This behavior helps developers choose their preferred config format while maintaining a clear loading order.

Practice

(1/5)
1. Which file format is a common alternative to application.yml in Spring Boot for configuration?
easy
A. config.ini
B. config.xml
C. settings.json
D. application.properties

Solution

  1. Step 1: Understand Spring Boot configuration files

    Spring Boot supports multiple configuration file formats, but the two most common are application.yml and application.properties.
  2. Step 2: Identify the alternative format

    The application.properties file uses simple key=value pairs and is widely used as an alternative to YAML files.
  3. Final Answer:

    application.properties -> Option D
  4. Quick Check:

    Alternative to application.yml = application.properties [OK]
Hint: Remember: properties files use key=value lines [OK]
Common Mistakes:
  • Confusing XML or JSON as default Spring Boot config
  • Thinking config.ini is supported by Spring Boot
  • Assuming YAML is the only option
2. Which of the following is the correct syntax for setting a server port in application.properties?
easy
A. server.port=8080
B. server.port => 8080
C. server.port : 8080
D. server.port -> 8080

Solution

  1. Step 1: Recall properties file syntax

    In application.properties, each configuration is set as a key=value pair without colons or arrows.
  2. Step 2: Identify the correct key-value format

    The correct syntax uses an equals sign: server.port=8080.
  3. Final Answer:

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

    Properties syntax uses = not : or arrows [OK]
Hint: Properties files always use key=value format [OK]
Common Mistakes:
  • Using colon instead of equals sign
  • Using arrow symbols which are invalid
  • Mixing YAML syntax with properties syntax
3. Given the following application.properties snippet:
spring.datasource.url=jdbc:mysql://localhost:3306/mydb
spring.datasource.username=root
spring.datasource.password=pass123

What is the effect of this configuration?
medium
A. It sets up a PostgreSQL database connection.
B. It configures a MySQL database connection with the specified URL and credentials.
C. It disables the datasource configuration.
D. It causes a syntax error and fails to start.

Solution

  1. Step 1: Analyze the datasource properties

    The keys spring.datasource.url, username, and password configure the database connection details.
  2. Step 2: Identify the database type and credentials

    The URL contains jdbc:mysql://, indicating a MySQL database with host localhost and database mydb. Username and password are set accordingly.
  3. Final Answer:

    It configures a MySQL database connection with the specified URL and credentials. -> Option B
  4. Quick Check:

    Datasource URL with jdbc:mysql = MySQL config [OK]
Hint: Look for jdbc:mysql in URL to identify MySQL config [OK]
Common Mistakes:
  • Assuming PostgreSQL from MySQL URL
  • Thinking this disables datasource
  • Confusing syntax as error
4. You wrote this in application.properties:
server.port9090

Why does your Spring Boot app fail to start on port 9090?
medium
A. Spaces are not allowed anywhere in properties files.
B. Port 9090 is reserved and cannot be used.
C. Missing equals sign between key and value causes syntax error.
D. Property name is incorrect; should be server.port.number.

Solution

  1. Step 1: Check properties file syntax

    Each line must have a key and value separated by an equals sign (=) or colon (:).
  2. Step 2: Identify the missing equals sign

    The line server.port9090 lacks the equals sign, causing it to be parsed as a single key with no value and preventing the port from being set.
  3. Final Answer:

    Missing equals sign between key and value causes syntax error. -> Option C
  4. Quick Check:

    Properties need key=value format [OK]
Hint: Always use = or : between key and value [OK]
Common Mistakes:
  • Omitting equals sign
  • Using wrong property name
  • Assuming spaces are forbidden everywhere
5. You want to migrate your Spring Boot app configuration from application.yml to application.properties. Which of the following is the correct way to convert this YAML snippet?
server:
  port: 9090
spring:
  datasource:
    url: jdbc:h2:mem:testdb
    username: sa
    password: ""
hard
A. server.port=9090 spring.datasource.url=jdbc:h2:mem:testdb spring.datasource.username=sa spring.datasource.password=
B. server.port : 9090 spring.datasource.url : jdbc:h2:mem:testdb spring.datasource.username : sa spring.datasource.password : ""
C. server.port => 9090 spring.datasource.url => jdbc:h2:mem:testdb spring.datasource.username => sa spring.datasource.password => ""
D. server.port9090 spring.datasource.urljdbc:h2:mem:testdb spring.datasource.usernamesa spring.datasource.password""

Solution

  1. Step 1: Understand YAML to properties conversion

    YAML uses indentation and colons, while properties files use dot notation and equals signs.
  2. Step 2: Convert nested YAML keys to dot notation with =

    The nested keys become dot-separated keys, and values are assigned with equals signs. Empty password is represented by an empty value.
  3. Final Answer:

    server.port=9090 spring.datasource.url=jdbc:h2:mem:testdb spring.datasource.username=sa spring.datasource.password= -> Option A
  4. Quick Check:

    YAML nesting = dot notation + = in properties [OK]
Hint: Convert YAML nesting to dot keys with = [OK]
Common Mistakes:
  • Using colon instead of equals in properties
  • Using arrows or spaces instead of =
  • Not converting nested keys to dot notation
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