Recall & Review
beginner
What is the purpose of environment variables in Spring Boot configuration?
Environment variables allow you to externalize configuration from your Spring Boot application. This means you can change settings like database URLs or API keys without changing the code, making your app flexible and secure.
Click to reveal answer
beginner
How do you reference an environment variable in Spring Boot's application.properties file?
You use the syntax
${ENV_VAR_NAME}. For example, spring.datasource.url=${DB_URL} will use the value of the environment variable DB_URL.Click to reveal answer
intermediate
What happens if an environment variable used in Spring Boot configuration is not set?
If the environment variable is missing and no default value is provided, Spring Boot will throw an error on startup. You can provide a default like
${ENV_VAR_NAME:defaultValue} to avoid this.Click to reveal answer
beginner
How can you set environment variables for a Spring Boot app when running it locally?
You can set environment variables in your operating system or use command line before running the app, for example:
DB_URL=jdbc:mysql://localhost:3306/mydb ./mvnw spring-boot:run or set them in your IDE run configuration.Click to reveal answer
beginner
Why is using environment variables for configuration considered a good practice in Spring Boot?
It keeps sensitive data like passwords out of your codebase, allows different settings per environment (dev, test, prod), and makes your app easier to deploy and maintain.
Click to reveal answer
How do you inject an environment variable named 'API_KEY' into Spring Boot's application.properties?
✗ Incorrect
The correct syntax is
${API_KEY} to reference environment variables in Spring Boot properties.What will happen if you use
${DB_PASS} in configuration but 'DB_PASS' is not set and no default is given?✗ Incorrect
Missing environment variables without defaults cause Spring Boot to fail startup to avoid misconfiguration.
Which of these is a good reason to use environment variables in Spring Boot config?
✗ Incorrect
Environment variables help keep configuration flexible and secure across different environments.
How can you provide a default value for an environment variable in Spring Boot properties?
✗ Incorrect
The syntax
${VAR_NAME:defaultValue} sets a default if the environment variable is missing.Where can environment variables be set for a Spring Boot app running in production?
✗ Incorrect
Environment variables are typically set in the OS or container environment where the app runs.
Explain how environment variables improve configuration management in Spring Boot applications.
Think about how changing settings without code changes helps.
You got /4 concepts.
Describe the syntax and usage of environment variables in Spring Boot's application.properties file.
Focus on how to write the variable and handle missing values.
You got /4 concepts.