0 day streak
java / beginner
Snippet

Environment-Specific Logic with @Profile

Profiles allow you to register beans only in certain environments. For example, you can load a specific bean for 'dev' and a different one for 'prod'.

snippet.java
java
1
2
3
4
5
@Component
@Profile("dev")
public class DevDataSource {
// Logic specifically for development environments
}
spring
Breakdown
1
@Profile("dev")
Tells Spring to only instantiate this class if the 'dev' profile is currently active.