Member-only story
Customize Default Configuration in Spring Boot | 5 Proven Ways
Learn how to override and customize Spring Boot’s default configuration using properties, custom beans, profiles, and auto-configuration exclusions.
Introduction
Spring Boot offers opinionated defaults that make setup fast. But what if you need different settings?
The good news: Spring Boot lets you override or extend these defaults easily — without disabling everything.
Let’s explore 5 common and powerful ways to customize Spring Boot’s default configuration.
🔹 1. Customize with application.properties
or application.yml
This is the most common way to tweak default values.
🔧 Example: Change server port
server.port=9090
🔧 Example: Configure datasource
spring.datasource.url=jdbc:mysql://localhost:3306/mydb
spring.datasource.username=root
spring.datasource.password=secret
📌 Use this for:
- Server settings
- DB connections
- Logging
- Caching
- JPA & Hibernate settings
🗂️ You can also use application.yml
if you prefer YAML syntax.
🔹 2. Customize with Profiles (application-dev.properties
, etc.)
You can define different configs for different environments using Spring Profiles.
🔧 Example:
application-dev.properties
for devapplication-prod.properties
for production
Then activate the profile in your application.properties
:
spring.profiles.active=dev
Or use CLI:
java -jar app.jar --spring.profiles.active=prod
🔁 Great for customizing behavior by environment.
🔹 3. Override AutoConfigured Beans
Spring Boot only configures beans if they don’t already exist (thanks to @ConditionalOnMissingBean
).