Jānis Ošs’ Post

🚀 Spring Profiles — The Right Config for Every Environment Ever deployed to production with dev credentials still in the code? Spring Profiles are here to save you. Spring Boot's Profile system lets you define environment-specific beans and configurations without touching a single line of business logic. Here's the core idea: @Configuration @Profile("dev") public class DevDataSourceConfig { @Bean public DataSource dataSource() { return new EmbeddedDatabaseBuilder().build(); // H2 in-memory } } @Configuration @Profile("prod") public class ProdDataSourceConfig { @Bean public DataSource dataSource() { // Real PostgreSQL pool return DataSourceBuilder.create().url("jdbc:postgresql://...").build(); } } Pair this with application-dev.yml and application-prod.yml, then activate via: SPRING_PROFILES_ACTIVE=prod java -jar app.jar ✅ Clean separation of concerns ✅ No if/else config logic in code ✅ Works seamlessly with Docker, Kubernetes, CI/CD pipelines This is one of those features that looks simple but has a huge impact on production safety and developer experience. #Java #SpringBoot #BackendDevelopment #SoftwareEngineering #CleanCode

To view or add a comment, sign in

Explore content categories