Ashutosh Mishra’s Post

Your dev database should never be your prod database. Spring Profiles solve this cleanly. Step 1: Create environment-specific config files application-dev.propertiesspring.datasource.url=jdbc:h2:mem:testdbspring.jpa.show-sql=true https://lnkd.in/g2EGtgX3spring.datasource.url=jdbc:mysql://prod-server/mydbspring.jpa.show-sql=false → logging.level.root=WARN Step 2: Activate the profile # Run with dev profile java -jar app.jar --spring.profiles.active=dev # Or set in application.properties spring.profiles.active=dev Step 3: Profile-specific beans @Configuration @Profile("prod") public class ProdSecurityConfig {  // only loads in production } @Configuration @Profile("dev") public class DevSecurityConfig {  // only loads in development } Now your app behaves differently per environment — automatically. No more commenting out database URLs before pushing to prod. #Java #SpringBoot #SpringProfiles #BackendDevelopment #LearningInPublic

To view or add a comment, sign in

Explore content categories