Spring Boot Application Properties
1. Introduction
In Spring Boot, configuration is managed using:
application.yml
These files help to:
Customize application behavior
Avoid changing source code
Manage environment-specific settings
2. Why Use application.properties
Centralized configuration
Easy to override default settings
Supports multiple environments (dev, test, prod)
Reduces hardcoding
3. File Location
Configuration file is placed inside:
plaintext
src/main/resources4. Server Configuration
Change default port (8080):
plaintext
server.port=89895. Application Name
Set application name:
plaintext
spring.application.name=my-app6. Database Configuration
MySQL Example
plaintext
spring.datasource.url=jdbc:mysql://localhost:3306/mydb
spring.datasource.username=root
spring.datasource.password=1234
spring.datasource.driver-class-name=com.mysql.cj.jdbc.DriverPostgreSQL Example
plaintext
spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.username=postgres
spring.datasource.password=1234MongoDB Example
plaintext
spring.data.mongodb.uri=mongodb://localhost:27017/mydb7. JPA (Hibernate) Configuration
plaintext
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true8. Eureka Server Configuration
plaintext
eureka.client.service-url.defaultZone=http://localhost:8761/eureka/
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true9. application.yml (Alternative)
YAML format is more readable for complex configurations.
Example
plaintext
server:
port: 8989
spring:
application:
name: my-app
datasource:
url: jdbc:mysql://localhost:3306/mydb
username: root
password: 123410. Key Points
Properties file uses key-value format
YAML uses hierarchical structure
Both are used for configuration
YAML is preferred for large projects
11. Conclusion
application.properties is simple and widely used
application.yml is more readable for complex setups
Helps manage configuration without changing code