Spring Profiles provide a powerful way to segregate parts of your application configuration and beans based on the environment (e.g., dev, test, prod).
What are Spring Profiles?
Spring Profiles allow you to define different configurations for different environments and conditionally load beans or properties.
java
@Profile("dev")
@Bean
public DataSource devDataSource() {
// Dev-specific bean
}
What Do Profiles Control?
@Component
, @Configuration
, @Service
, etc.)application.properties
or .yml
filesWhy do we need Spring Profiles?
When to use Spring Profiles?