Setting the file. One moment.
Skill 114 · Create Spring Boot Java Project
Subchapter 114.1
references/configuration.mdMarkdown2 KBView on GitHub
Use application.properties or application.yml, matching what the project already uses. New projects generated by start.spring.io get application.properties; YAML is fine for deeply nested settings. Do not mix both in one project.
# application.properties (shared defaults)
spring.application.name=demo
spring.jpa.open-in-view=false
server.shutdown=gracefulapplication-dev.properties, application-prod.properties, activated with SPRING_PROFILES_ACTIVE (environment variable) or --spring.profiles.active.logging.level.com.example=DEBUG).src/test/resources/application.properties or @TestPropertySource, not a “test” profile checked into main.spring.datasource.url=${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/mydb}.SPRING_DATASOURCE_URL to spring.datasource.url automatically (relaxed binding)..env file: spring.config.import=optional:file:.env[.properties]. Add .env to .gitignore; commit .env.sample with placeholder values.spring.config.import=configtree:/run/secrets/).@ConfigurationProperties(prefix = "app.mail")
@Validated
public record MailProperties(@NotBlank String from, @Positive int retries) {}Enable with @ConfigurationPropertiesScan on the application class (or @EnableConfigurationProperties). Prefer this over scattered @Value. Spring Boot’s annotation processor (spring-boot-configuration-processor, optional dependency) generates IDE metadata.
@ConfigurationProperties with validation for custom settings