Tutorials/Spring Boot/Spring Boot
Lesson

Spring Boot Application Properties

Spring Boot /Spring Boot

Spring Boot Application Properties

1. Introduction

In Spring Boot, configuration is managed using:

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/resources

4. Server Configuration

Change default port (8080):

plaintext
server.port=8989

5. Application Name

Set application name:

plaintext
spring.application.name=my-app

6. 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.Driver

PostgreSQL Example

plaintext
spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.username=postgres
spring.datasource.password=1234

MongoDB Example

plaintext
spring.data.mongodb.uri=mongodb://localhost:27017/mydb

7. JPA (Hibernate) Configuration

plaintext
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

8. Eureka Server Configuration

plaintext
eureka.client.service-url.defaultZone=http://localhost:8761/eureka/
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true

9. 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: 1234

10. 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