What is Spring Boot application.properties/application.yaml?
Answer
Spring Boot uses application.properties or application.yaml (in src/main/resources/) as the primary configuration file for setting application properties. They configure both Spring Boot auto-configuration and custom application settings. Properties format: server.port=8080 spring.datasource.url=jdbc:postgresql://localhost:5432/mydb spring.datasource.username=postgres spring.datasource.password=secret spring.jpa.hibernate.ddl-auto=validate spring.jpa.show-sql=true logging.level.com.example=DEBUG app.jwt.secret=mySecretKey app.max-upload-size=10MB. YAML format (recommended for hierarchy): server: port: 8080 spring: datasource: url: jdbc:postgresql://localhost:5432/mydb username: postgres jpa: show-sql: true app: jwt: secret: mySecretKey. Profiles: create application-dev.properties, application-prod.properties — activated with spring.profiles.active=dev. External config: Spring Boot loads properties in priority order: 1. Command-line args (--server.port=9090); 2. Environment variables (SPRING_DATASOURCE_URL); 3. application-{profile}.properties; 4. application.properties. @Value injection: @Value("${app.jwt.secret}") private String jwtSecret;. @ConfigurationProperties: bind a prefix to a POJO for type-safe configuration: @ConfigurationProperties(prefix = "app.jwt") public class JwtProperties { private String secret; private int expiration; }.
Previous
What are Spring MVC request mapping annotations?
Next
What is Dependency Injection in Spring?