Your laptop uses a local database; the production server uses a different one with real passwords. Spring Boot handles this with application properties and profiles, so the same code runs everywhere with the right settings.
application.properties
Settings live in src/main/resources/application.properties (or application.yml):
server.port=8080
spring.datasource.url=jdbc:mysql://localhost:3306/coursedb
app.page-size=20
You can define your own keys, like app.page-size, and read them with @Value("${app.page-size}") or, better for groups of settings, a class annotated with @ConfigurationProperties(prefix = "app").
Profiles
Create one file per environment:
application-dev.properties: local database, detailed logging.application-prod.properties: production database, less logging.
Activate a profile with spring.profiles.active=dev, or when starting the app: java -jar app.jar --spring.profiles.active=prod. Settings in the profile file override the shared application.properties.
Keep secrets out of Git
Never commit real passwords. Reference environment variables instead: spring.datasource.password=${DB_PASSWORD}. On a server or in Docker, set DB_PASSWORD as an environment variable. Environment variables also override properties directly, which is how most cloud platforms configure apps.
Beans for one profile only
Add @Profile("dev") to a class to create it only in development, for example a component that loads sample data.
Common mistakes
- Forgetting to activate a profile, so the app silently uses default settings.
- Typos in property names, which Spring ignores without an error.
- Committing
application-prod.propertieswith real credentials.
Related: Spring Boot with MySQL and Spring Boot: your first REST API.
These topics are practised with projects and mock interviews in our Java Full Stack course in Bangalore.
Book a free demo class at our BTM Layout centre, and ask a counsellor for batch details.
