Consider a Spring Boot application with multiple profiles defined: dev, test, and prod. If the application is started with the JVM argument -Dspring.profiles.active=test, what will be the active profile during runtime?
Think about how Spring Boot reads the spring.profiles.active property.
Spring Boot activates only the profile specified by spring.profiles.active. JVM arguments like -Dspring.profiles.active=test set this property, so only the test profile is active.
Given the following YAML configuration, which option correctly sets the active profile to prod?
spring:
profiles:
active: ???Remember how simple string values are set in YAML.
The spring.profiles.active property expects a simple string or comma-separated string. The correct YAML is active: prod. Using a list is not the standard way here. Using quotes is allowed but unnecessary.
Given these two files:
application.properties: spring.profiles.active=dev application-dev.properties: logging.level.root=DEBUG
The application logs do not show DEBUG level logs. What is the most likely cause?
Check if any external settings override the active profile.
Spring Boot allows overriding spring.profiles.active via environment variables or JVM arguments, which take precedence over application.properties. If such an override exists, the dev profile won't activate.
Consider this Spring Boot component:
@Component
@Profile("prod")
public class ProdService {
public String getMessage() {
return "Production Service";
}
}If the active profile is dev, what happens when the application tries to get ProdService bean?
Think about how @Profile controls bean creation.
The @Profile("prod") annotation means the bean is only created if the prod profile is active. If the active profile is dev, the bean is not created, so requesting it causes NoSuchBeanDefinitionException.
If a Spring Boot application activates two profiles simultaneously: dev and featureX, and both have application-dev.properties and application-featureX.properties files with overlapping keys, how does Spring Boot resolve the final property values?
Consider the order of profiles in the spring.profiles.active property.
Spring Boot loads profile-specific properties in the order they are listed in spring.profiles.active. Later profiles override properties from earlier ones if keys overlap.