Bird
0
0

You want to configure a Spring Boot app to use an environment variable REDIS_URL, but if it's missing, fallback to localhost. Which application.properties line achieves this?

hard📝 Application Q8 of 15
Spring Boot - Application Configuration
You want to configure a Spring Boot app to use an environment variable REDIS_URL, but if it's missing, fallback to localhost. Which application.properties line achieves this?
Aredis.url=${REDIS_URL} || localhost
Bredis.url=${REDIS_URL?localhost}
Credis.url=%REDIS_URL%:localhost
Dredis.url=${REDIS_URL:localhost}
Step-by-Step Solution
Solution:
  1. Step 1: Recall Spring Boot syntax for default environment variable values

    Use ${VAR_NAME:default} to provide fallback if env var is missing.
  2. Step 2: Match correct syntax for REDIS_URL fallback

    The correct line is redis.url=${REDIS_URL:localhost}.
  3. Final Answer:

    redis.url=${REDIS_URL:localhost} -> Option D
  4. Quick Check:

    Default fallback syntax = ${VAR:default} [OK]
Quick Trick: Use ${VAR:default} for fallback values in Spring Boot config [OK]
Common Mistakes:
  • Using shell or Windows syntax for defaults
  • Using invalid operators like || or ? in properties
  • Forgetting to wrap variable in ${}

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes