Bird
0
0

In application.yml, you wrote:

medium📝 Debug Q7 of 15
Spring Boot - Application Configuration
In application.yml, you wrote:
db:
  host: ${DB_HOST}
  port: ${DB_PORT:3306}

At runtime, you get an error about DB_HOST but not about DB_PORT. Why?
ADB_HOST is not set and has no default; DB_PORT has a default value
BDB_PORT is set but DB_HOST is ignored
CYAML syntax is invalid for DB_HOST
DSpring Boot does not support defaults in YAML
Step-by-Step Solution
Solution:
  1. Step 1: Check environment variable usage with and without defaults

    DB_HOST has no default, so if unset, causes error. DB_PORT has default 3306, so no error if unset.
  2. Step 2: Understand error behavior

    Missing DB_HOST causes unresolved placeholder error; DB_PORT uses default silently.
  3. Final Answer:

    DB_HOST is not set and has no default; DB_PORT has a default value -> Option A
  4. Quick Check:

    Missing env var without default causes error [OK]
Quick Trick: Always provide defaults or set env vars to avoid errors [OK]
Common Mistakes:
  • Assuming missing env vars never cause errors
  • Confusing YAML syntax with env var issues
  • Thinking Spring Boot ignores missing variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes