The application.properties file helps you set up your Spring Boot app's settings in one place. It makes changing app behavior easy without touching code.
0
0
Application.properties basics in Spring Boot
Introduction
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 add custom settings your app can read.
You want to change email or API keys without changing code.
Syntax
Spring Boot
property.name=value
Each line sets one property with a name and a value separated by =.
Use dot notation to organize properties, like server.port=8080.
Examples
Sets the app to run on port 8080.
Spring Boot
server.port=8080Configures the database connection URL.
Spring Boot
spring.datasource.url=jdbc:mysql://localhost:3306/mydbTurns on debug logging for Spring framework classes.
Spring Boot
logging.level.org.springframework=DEBUG
Defines a custom property your app can read.
Spring Boot
app.custom.message=Hello from properties!Sample Program
This Spring Boot app reads a custom message from application.properties and shows it at the home page.
Spring Boot
package com.example.demo; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } } @RestController class HelloController { @Value("${app.custom.message}") private String message; @GetMapping("/") public String hello() { return message; } }
OutputSuccess
Important Notes
Remember to place application.properties in src/main/resources folder.
Changes in application.properties require app restart to take effect.
You can override properties with environment variables or command line args.
Summary
application.properties stores app settings in key=value lines.
It helps configure ports, databases, logging, and custom values.
Spring Boot reads these properties automatically when the app starts.