Spring Boot - Application Properties

Last Updated : 7 Mar, 2026

In Spring Boot applications, configuration is important for customizing application behavior without modifying the source code. Spring Boot allows developers to manage settings using configuration files like application.properties or application.yml.

  • These files help define settings such as server port, database configuration, and logging levels.
  • They make the application easier to maintain and allow different configurations for different environments.
File
Folder-Structure

Why Use application.properties?

  • Centralized configuration management.
  • Easy to override default Spring Boot settings.
  • Provides flexibility for different environments (dev, test, prod).
  • Reduces hardcoding in source code.

Commonly Used Properties

1. Server Configuration

We can change the default port (8080) of a Spring Boot application by setting the property server.port in the application.properties file. For example: server.port=8989

2. Defining the Application Name

We can set a custom name for your Spring Boot application using the spring.application.name property in the application.properties.

ou
Application

This represents the property as a key-value pair, where each key is associated with a corresponding value.

2. Database Configuration

To connect your Spring Boot application with a database, specify the required properties such as spring.datasource.url, spring.datasource.username and spring.datasource.password in the application.properties file. These properties vary depending on the database (e.g., MySQL, PostgreSQL, Oracle).

For MySQL Database:

ou
MY-SQL

For PostgreSQL Database

ou

For MongoDB

ou

Hibernate (JPA) Settings

ou

3. Connecting with an Eureka Server

Eureka Server acts as a service registry in microservices architecture. Each microservice registers itself to Eureka, which maintains service discovery details.

ou

Note: The values provided are sample data. Please update them according to your database configuration. However, the keys remain the same.

Using application.yml Instead of application.properties

The application.properties file is not very readable when dealing with complex configurations. Most developers prefer using application.yml (YAML format) instead. YAML is a superset of JSON and provides a more structured and readable way to define hierarchical configuration data. Let's convert some of the previous examples into YAML format.

Case 1: Connecting with a MySQL Database

Let’s pick above example 3 where we were connecting with the MySQL Database, the corresponding properties will be as follows:

ou
application.yml

Case 2: Connecting with an Eureka Server

Let's pick above example 6 where we were connecting with the Eureka Server, the corresponding properties will be as follows:

ou
Eureka Server
Comment

Explore