Performance: Environment-based profiles
This concept affects application startup time and resource loading by selecting configuration sets based on environment.
Spring Boot application activates only one profile at startup (e.g., -Dspring.profiles.active=prod) to load relevant configs
Spring Boot application loads all configurations for dev, test, and prod environments regardless of active profile
| Pattern | Config Loading | Startup Delay | Resource Usage | Verdict |
|---|---|---|---|---|
| Load all profiles configs | Loads all config files | High (200-500ms extra) | High (unused beans/resources) | [X] Bad |
| Activate single profile | Loads only active profile config | Low (minimal delay) | Low (only needed beans) | [OK] Good |
What is the main purpose of using profiles in a Spring Boot application?
Which of the following is the correct way to activate a profile named dev in application.properties?
spring.profiles.active.Given the following Spring Boot code snippet, what will be printed if the active profile is prod?
@Component
@Profile("dev")
public class DevService {
public DevService() {
System.out.println("DevService active");
}
}
@Component
@Profile("prod")
public class ProdService {
public ProdService() {
System.out.println("ProdService active");
}
}prod, so only beans with @Profile("prod") will be created.ProdService constructor runs, printing "ProdService active".Consider this Spring Boot configuration snippet in application.properties:
spring.profiles.active=dev,prod
What is the problem with this configuration?
You want to create a bean that only loads when test profile is active and another bean that loads for all profiles except test. Which annotation setup is correct?
!test means the second bean loads when test is not active.Pass the test and this pattern moves unknown