Spring Boot YAML vs Properties: Configuration Comparison and Interview Questions 2026

Compare application.yml and application.properties in Spring Boot 4.1: syntax, multi-profile files, precedence rules, Jasypt-encrypted secrets, and the configuration questions asked in interviews.

Spring Boot YAML vs Properties configuration comparison illustration

Spring Boot supports two configuration formats out of the box: YAML (application.yml) and Properties (application.properties). Both achieve the same goal, but they differ in syntax, readability, and specific use cases. This comparison breaks down the practical differences and covers the interview questions that come up around Spring Boot externalized configuration.

Quick Decision Guide

Use YAML for projects with deeply nested configuration or multiple profiles. Use Properties for simple flat configurations or when working with teams unfamiliar with YAML syntax.

Spring Boot Properties vs YAML at a Glance

On Spring Boot 4.1, the current release line, both formats feed the same Environment and bind identically. The differences are syntax, a few loading rules, and what happens when both files exist.

FeatureYAMLProperties
Nested configurationNative hierarchyDot notation
Multi-profile in one file--- separator#--- or !--- separator
List syntaxNative YAML arraysIndex notation [0], [1]
Comments# on any line# or ! on any line
Loadable with @PropertySourceNoYes
Both files in the same locationOverriddenTakes precedence
Learning curveIndentation-sensitiveMinimal

The last two rows are the ones candidates usually miss. The Spring Boot external configuration reference states that YAML files cannot be loaded through @PropertySource or @TestPropertySource, and that when application.properties and application.yml sit side by side, the .properties value wins. The official recommendation is to pick one format for the whole application.

Syntax Comparison Between YAML and Properties

The most visible difference is how each format represents hierarchical data. Properties files use dot notation on every line, while YAML uses indentation to express nesting.

properties
# application.properties
server.port=8080
server.servlet.context-path=/api
spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.username=admin
spring.datasource.password=${DB_PASSWORD}
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.show-sql=false

The equivalent YAML configuration groups related settings visually:

yaml
# application.yml
server:
  port: 8080
  servlet:
    context-path: /api

spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/mydb
    username: admin
    password: ${DB_PASSWORD}
  jpa:
    hibernate:
      ddl-auto: validate
    show-sql: false

YAML reduces repetition when multiple properties share the same prefix. In the properties file, spring.datasource appears three times, while YAML declares it once.

Profile Management in Spring Boot Configuration

Spring Boot profiles allow different configurations for development, staging, and production environments. Both formats support profile-specific files and multi-document files.

The classic approach uses one file per profile:

properties
# application-dev.properties
server.port=8080
spring.datasource.url=jdbc:h2:mem:devdb
logging.level.root=DEBUG

# application-prod.properties
server.port=80
spring.datasource.url=jdbc:postgresql://prod-server:5432/proddb
logging.level.root=WARN

YAML supports multi-document syntax within a single file using the --- separator:

yaml
# application.yml
spring:
  profiles:
    active: dev

---
spring:
  config:
    activate:
      on-profile: dev
server:
  port: 8080
logging:
  level:
    root: DEBUG

---
spring:
  config:
    activate:
      on-profile: prod
server:
  port: 80
logging:
  level:
    root: WARN

Properties files support the same multi-document layout. A line containing only #--- (or !---) splits the file into documents:

properties
# application.properties
spring.profiles.active=dev
#---
spring.config.activate.on-profile=dev
server.port=8080
logging.level.root=DEBUG
#---
spring.config.activate.on-profile=prod
server.port=80
logging.level.root=WARN

The separator must have no leading whitespace and exactly three hyphens. Since Spring Boot 2.4, the spring.config.activate.on-profile property replaced the older spring.profiles syntax, in both formats.

Interview trap

"Properties files need one file per profile" is a common wrong answer. Multi-document .properties files have existed since Spring Boot 2.4. The real limitation of YAML runs the other way: it cannot be loaded with @PropertySource.

Profile activation, groups and @Profile beans are drilled in the profiles and environment interview module.

Lists and Complex Data Structures

YAML excels at representing lists and nested structures. This matters for configurations like security rules, CORS mappings, or custom beans.

yaml
# application.yml
app:
  security:
    allowed-origins:
      - https://sharpskill.dev
      - https://api.sharpskill.dev
    cors:
      allowed-methods:
        - GET
        - POST
        - PUT
        - DELETE
    jwt:
      secret: ${JWT_SECRET}
      expiration-ms: 86400000

The properties equivalent requires index notation:

properties
# application.properties
app.security.allowed-origins[0]=https://sharpskill.dev
app.security.allowed-origins[1]=https://api.sharpskill.dev
app.security.cors.allowed-methods[0]=GET
app.security.cors.allowed-methods[1]=POST
app.security.cors.allowed-methods[2]=PUT
app.security.cors.allowed-methods[3]=DELETE
app.security.jwt.secret=${JWT_SECRET}
app.security.jwt.expiration-ms=86400000

Adding a new origin to the YAML file means appending a line. In properties, every existing index must stay correct, and the new entry needs the next index number.

Ready to ace your Spring Boot interviews?

Practice with our interactive simulators, flashcards, and technical tests.

Type-Safe Configuration with @ConfigurationProperties

Spring Boot binds configuration values to Java classes through @ConfigurationProperties. Both formats work identically with this annotation.

AppSecurityProperties.javajava
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.List;

@ConfigurationProperties(prefix = "app.security")
public record AppSecurityProperties(
    List<String> allowedOrigins,
    CorsConfig cors,
    JwtConfig jwt
) {
    public record CorsConfig(List<String> allowedMethods) {}
    public record JwtConfig(String secret, long expirationMs) {}
}

Spring Boot relaxed binding converts between different naming conventions automatically. The property app.security.allowed-origins binds to allowedOrigins regardless of whether the source is YAML or properties.

SecurityConfig.javajava
import org.springframework.context.annotation.Configuration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;

@Configuration
@EnableConfigurationProperties(AppSecurityProperties.class)
public class SecurityConfig {
    
    private final AppSecurityProperties securityProperties;
    
    public SecurityConfig(AppSecurityProperties securityProperties) {
        this.securityProperties = securityProperties;
    }
    
    // CORS configuration using securityProperties.cors().allowedMethods()
}

For more on Spring Security configuration patterns, see the Spring Security basics module.

Common Interview Questions About Spring Boot Configuration

Configuration is a frequent topic in Spring Boot interviews. Interviewers assess understanding of externalized configuration, environment-specific settings, and property binding.

Question: What is the order of precedence for configuration sources?

Spring Boot loads configuration from multiple sources in a specific order. Higher precedence sources override lower ones (simplified from the official list, which also covers JNDI, servlet parameters and test annotations):

  1. Command-line arguments (--server.port=9000)
  2. SPRING_APPLICATION_JSON (inline JSON in an environment variable or system property)
  3. Java system properties (-Dserver.port=9000)
  4. OS environment variables (SERVER_PORT=9000)
  5. Config data files (application.yml, application.properties and their profile variants)
  6. @PropertySource annotations
  7. Default properties via SpringApplication.setDefaultProperties

Inside step 5 there is a second ordering: profile-specific files override generic ones, and files outside the packaged jar override files inside it. Within one location, .properties overrides .yml. A candidate who can explain why a value set in application.yml is silently ignored (a leftover application.properties next to it) shows real debugging experience.

Question: When would you choose properties over YAML?

Properties files have advantages in specific situations:

  • @PropertySource loading: YAML cannot be loaded this way, so extra files imported through the annotation must be .properties
  • Team familiarity: Properties syntax is simpler for developers new to Spring Boot
  • Single-line values: Flat configurations without nesting gain nothing from YAML
  • No indentation errors: a misplaced space in YAML silently moves a key under the wrong parent

YAML works better when:

  • Configuration has deep nesting (three or more levels)
  • Lists require frequent modification
  • Readability matters for complex configurations

Question: How do you handle sensitive configuration values?

Never commit secrets to version control. Spring Boot provides several approaches:

yaml
# application.yml - reference environment variable
spring:
  datasource:
    password: ${DB_PASSWORD}

For production systems, Spring Cloud Config Server or HashiCorp Vault provide centralized secret management. The Actuator monitoring guide covers securing sensitive endpoints.

Question: What is Jasypt and how does it encrypt Spring Boot properties?

Jasypt Spring Boot decrypts values wrapped in ENC(...) when the Environment is built, so encrypted secrets can live in application.yml or application.properties and still bind like plain values:

properties
# application.properties
spring.datasource.password=ENC(nrmZtkF7T0kjG/VodDvBw93Ct8EgjCA+)
bash
# The master password is supplied at runtime, never committed
java -Djasypt.encryptor.password=$JASYPT_MASTER_KEY -jar app.jar

jasypt.encryptor.password is the only required property, and the default algorithm is PBEWITHHMACSHA512ANDAES_256. The format makes no difference: the same ENC(...) value works in YAML and properties.

The answer that separates a senior candidate: Jasypt does not remove the secret, it moves it. Whoever holds the master password can decrypt every value in the repository, and rotating it means re-encrypting all of them. Vault or a cloud secret manager adds access control, auditing and rotation, which Jasypt does not.

Check compatibility before upgrading

The 4.0.x starter (4.0.4, January 2026) requires Java 17 and Spring Boot 3.5+, and its README does not list Spring Boot 4. The underlying Jasypt library has had no release since 1.9.3 in May 2019. Verify the starter on a branch before moving a Jasypt-based project to Spring Boot 4.

Validating @ConfigurationProperties at Startup

Spring Boot validates @ConfigurationProperties classes at startup when combined with Jakarta Bean Validation annotations.

DatabaseProperties.javajava
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Positive;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;

@Validated
@ConfigurationProperties(prefix = "app.database")
public record DatabaseProperties(
    @NotBlank String url,
    @NotBlank String username,
    @Positive int poolSize
) {}

If app.database.pool-size is missing or negative, the application fails fast during startup with a clear error message. This validation works identically for YAML and properties sources.

Environment-Specific Configuration Files

Spring Boot supports additional configuration file locations beyond the default src/main/resources. The spring.config.import property loads external files:

yaml
# application.yml
spring:
  config:
    import:
      - optional:file:./config/
      - optional:configserver:http://config-server:8888

The optional: prefix prevents startup failure when the file does not exist. This pattern enables local development with default values while production pulls configuration from a central server. More practice questions on these files are in the application.properties and YAML interview module.

Sources

Start practicing!

Test your knowledge with our interview simulators and technical tests.

Key Takeaways for Spring Boot Configuration

  • YAML reduces repetition for configurations with shared prefixes and handles lists more cleanly
  • Properties files work well for flat configurations and teams less familiar with YAML syntax
  • Spring Boot 4.1 treats both formats equally for @ConfigurationProperties binding and validation
  • Both formats support several profiles in one file: --- in YAML, #--- in properties
  • When both files exist in the same location, .properties wins, and only properties files can be loaded with @PropertySource
  • Configuration precedence follows a defined order: command-line arguments override environment variables, which override file-based configuration
  • Sensitive values belong in environment variables or secret management systems; Jasypt ENC(...) values only move the secret to the master password
  • Use spring.config.import to load configuration from external sources in production environments
Daily challenge

Can you spot the bug in Spring Boot?

One real snippet, one hidden bug, one attempt a day. No account needed to try.

Anthony Fillion-Maillet

Written by

Anthony Fillion-Maillet

Founder of SharpSkill

Full-stack developer for over 10 years. Runs SharpSkill and answers for everything published here.

Updated on October 27, 2026

Tags

#spring-boot
#configuration
#yaml
#properties
#interview

Share

Related articles