Bird
0
0

Which of the following is the correct way to provide a default value for an environment variable PORT in application.yml?

easy📝 Conceptual Q2 of 15
Spring Boot - Application Configuration
Which of the following is the correct way to provide a default value for an environment variable PORT in application.yml?
Aserver: port: %PORT%:8080
Bserver: port: ${PORT:8080}
Cserver: port: $PORT || 8080
Dserver: port: PORT ? 8080
Step-by-Step Solution
Solution:
  1. Step 1: Recognize Spring Boot default value syntax in YAML

    Spring Boot uses ${VAR_NAME:default} to provide defaults for environment variables.
  2. Step 2: Confirm correct YAML indentation and syntax

    The correct YAML format is server:\n port: ${PORT:8080} to set port with default 8080.
  3. Final Answer:

    server: port: ${PORT:8080} -> Option B
  4. Quick Check:

    Default value syntax = ${PORT:8080} [OK]
Quick Trick: Use ${VAR:default} to set default environment variable values [OK]
Common Mistakes:
  • Using shell or Windows syntax for defaults
  • Incorrect YAML indentation
  • Using logical operators like || or ? which are invalid here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes