Spring Boot Application Properties
Application properties are the configuration settings for your Spring Boot app. They control the server port, database connections, logging level, and much more — all from a single file without touching Java code.
Where the File Lives
src/
└── main/
└── resources/
└── application.properties ← This file
Spring Boot automatically loads this file at startup. Every setting you place here overrides the built-in defaults.
Basic Syntax
key=value # Examples server.port=9090 spring.application.name=my-app logging.level.root=INFO
YAML Alternative
You can use application.yml instead. YAML uses indentation instead of dots to create hierarchy:
Properties format: YAML format:
────────────────────── ──────────────────────
server.port=9090 → server:
spring.application.name=app → port: 9090
spring:
application:
name: app
Both files do the same job. Use whichever format your team prefers. You cannot use both in the same project — pick one.
Most Commonly Used Properties
Server Settings
server.port=8080 # HTTP port server.servlet.context-path=/api # App runs at /api/* server.error.include-message=always # Show error messages
Datasource Settings
spring.datasource.url=jdbc:mysql://localhost:3306/mydb spring.datasource.username=root spring.datasource.password=secret spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
JPA Settings
spring.jpa.hibernate.ddl-auto=update # auto-create/update tables spring.jpa.show-sql=true # Print SQL to console spring.jpa.properties.hibernate.format_sql=true
Logging Settings
logging.level.root=INFO logging.level.com.estudy247=DEBUG # Debug only your package logging.file.name=app.log # Write logs to a file
Custom Properties
Define your own keys and read them in Java using @Value:
# In application.properties app.max-upload-size=10MB app.admin-email=admin@estudy247.com
// In Java
@Component
public class FileUploadService {
@Value("${app.max-upload-size}")
private String maxUploadSize;
@Value("${app.admin-email}")
private String adminEmail;
}
Binding Multiple Properties to a Class
For a group of related properties, use @ConfigurationProperties instead of multiple @Value annotations:
# application.properties app.mail.host=smtp.gmail.com app.mail.port=587 app.mail.username=noreply@estudy247.com
@Component
@ConfigurationProperties(prefix = "app.mail")
public class MailProperties {
private String host;
private int port;
private String username;
// Getters and setters
}
Spring maps each property to the matching field automatically. You get a single typed object instead of scattered @Value annotations.
Property Priority Diagram
Highest priority (wins)
│
▼
1. Command-line arguments java -jar app.jar --server.port=9090
2. Environment variables SERVER_PORT=9090
3. application-{profile}.properties
4. application.properties ← Default file
│
▼
Lowest priority (can be overridden)
This means you can override any setting at deployment time using environment variables — without changing any code or config files.
Hiding Sensitive Values
Never commit database passwords or API keys to version control. Use environment variables or a secrets manager instead:
# application.properties (safe to commit)
spring.datasource.password=${DB_PASSWORD}
# Your server environment (never commit this)
export DB_PASSWORD=actual_secret_password
Summary
application.propertiesorapplication.ymlcontrols all app settings- Use
@Valueto read a single custom property in Java - Use
@ConfigurationPropertiesto bind a group of related properties to a class - Environment variables and command-line args override file-based properties
- Keep secrets in environment variables — never commit them to code
