Complete the code to read an environment variable in Spring Boot application.properties.
server.port=[1]In Spring Boot, you use ${VAR:default} syntax to read environment variables with a default value.
Complete the annotation to inject an environment variable into a Spring Boot component.
@Value("[1]") private String dbUrl;
The @Value annotation uses ${} syntax and can include a default value after a colon.
Fix the error in this Spring Boot configuration to correctly use environment variables with default values.
spring.datasource.url=[1]The correct syntax uses ${VAR:default} with a colon to separate variable and default.
Fill both blanks to define a Spring Boot property that reads an environment variable with a fallback and inject it using @Value.
@Value("[1]") private String apiKey; # application.properties external.api.key=[2]
Use quotes and ${} syntax in @Value, and plain ${} syntax in properties file without quotes.
Fill all three blanks to create a configuration class that reads environment variables with defaults using @Value and exposes them as beans.
import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class AppConfig { @Value("[1]") private String host; @Value("[2]") private int port; @Bean public String serviceUrl() { return "http://" + host + ":" + [3]; } }
Use @Value with ${VAR:default} syntax for host and port, then use the port variable in the bean method.