0
0
Spring Bootframework~5 mins

application.properties structure in Spring Boot

Choose your learning style9 modes available
Introduction

The application.properties file holds settings that tell your Spring Boot app how to behave. It keeps configuration simple and organized.

You want to set the server port number for your app.
You need to configure database connection details like URL and username.
You want to enable or disable debug logging.
You want to set custom messages or feature flags for your app.
You want to configure email or security settings without changing code.
Syntax
Spring Boot
# key=value
server.port=8080
spring.datasource.url=jdbc:mysql://localhost:3306/mydb
logging.level.org.springframework=DEBUG

Each line has a key=value pair.

Keys use dots to group related settings, like server.port.

Examples
Sets the server to listen on port 8080.
Spring Boot
server.port=8080
Configures database login credentials.
Spring Boot
spring.datasource.username=root
spring.datasource.password=secret
Turns on detailed logging for Spring framework classes.
Spring Boot
logging.level.org.springframework=DEBUG
Custom flag to enable a feature in your app.
Spring Boot
app.featureX.enabled=true
Sample Program

This application.properties file sets the server port to 9090, configures an in-memory H2 database, sets logging level to INFO, and defines a welcome message.

Spring Boot
# application.properties
server.port=9090
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=sa
spring.datasource.password=
logging.level.root=INFO
app.welcome.message=Hello from Spring Boot!
OutputSuccess
Important Notes

Lines starting with # are comments and ignored.

Use consistent naming with dots to keep settings organized.

Changes to application.properties usually require restarting the app to take effect.

Summary

application.properties stores app settings as key=value pairs.

Use dots in keys to group related settings.

This file helps configure your app without changing code.