Spring Boot Configuration Properties Interview Questions and Answers

Master Spring Boot Configuration Properties with interview questions covering application.properties, application.yml, @ConfigurationProperties, @Value, profiles, external configuration, property binding, validation, and production best practices.


Introduction

Enterprise applications require different configurations for different environments such as Development, Testing, UAT, and Production.

Instead of hardcoding values in Java classes, Spring Boot supports Externalized Configuration, allowing applications to read configuration from multiple sources.

Spring Boot supports:

  • application.properties
  • application.yml
  • Environment Variables
  • JVM Arguments
  • Command Line Arguments
  • Kubernetes ConfigMaps
  • Docker Environment Variables
  • Cloud Configuration Servers

Configuration management is one of the most frequently asked Spring Boot interview topics.


Spring Boot Configuration Architecture

flowchart LR

ConfigurationSources --> SpringEnvironment

SpringEnvironment --> PropertyBinding

PropertyBinding --> ApplicationBeans

ConfigurationSources --> application.yml

ConfigurationSources --> EnvironmentVariables

ConfigurationSources --> CommandLine

ConfigurationSources --> ConfigServer

Q1. What is Externalized Configuration?

Answer

Externalized Configuration allows application settings to be stored outside the application code.

Instead of

String url =
"jdbc:mysql://localhost";

Use

spring.datasource.url=
jdbc:mysql://localhost

Benefits

  • No code changes per environment
  • Easier deployment
  • Improved security
  • Better maintainability

Q2. What are application.properties and application.yml?

Spring Boot supports both configuration formats.

application.properties

server.port=8080

spring.application.name=banking

application.yml

server:
  port: 8080

spring:
  application:
    name: banking

Comparison

Properties YAML
Key-value Hierarchical
Easy for small configs Better for large configs
More repetitive Cleaner structure

Q3. What is @Value?

@Value injects a single property into a bean.

Example

@Value("${server.port}")

private int port;

Advantages

  • Simple
  • Quick
  • Good for individual values

Limitations

  • Difficult for large configuration groups
  • No automatic validation
  • Less type-safe

Q4. What is @ConfigurationProperties?

@ConfigurationProperties binds a group of related properties into a strongly typed Java object.

Example

app:

  payment:

    timeout: 30

    currency: USD

Java Class

@ConfigurationProperties(
prefix="app.payment")

public class PaymentProperties {

    private int timeout;

    private String currency;

}

Binding Flow

flowchart LR

application.yml --> PropertyBinder

PropertyBinder --> PaymentProperties

PaymentProperties --> Service

Q5. @Value vs @ConfigurationProperties

@Value @ConfigurationProperties
Single property Group of properties
String-based Type-safe
No validation Supports validation
Good for small configs Best for enterprise applications

Use @ConfigurationProperties whenever multiple related properties exist.


Q6. How are Configuration Properties validated?

Spring Boot integrates with Bean Validation.

Example

@NotBlank

private String url;

@Min(1)

private int timeout;

Configuration

@Validated

@ConfigurationProperties(
prefix="database")

Benefits

  • Fail-fast startup
  • Detect invalid configuration early
  • Improved reliability

Q7. What is the Property Resolution Order?

When the same property exists in multiple locations,

Spring Boot follows a precedence order.

Simplified order

  1. Command-line arguments
  2. JVM System Properties
  3. Environment Variables
  4. application.yml / application.properties
  5. Default values

Resolution Flow

flowchart TD

CommandLine --> SpringEnvironment

JVMProperties --> SpringEnvironment

EnvironmentVariables --> SpringEnvironment

ApplicationYML --> SpringEnvironment

SpringEnvironment --> FinalValue

The highest-priority source overrides lower-priority sources.


Q8. How do Profiles work with Configuration?

Example

application.yml

application-dev.yml

application-test.yml

application-prod.yml

Activate Profile

spring.profiles.active=prod

Architecture

flowchart LR

Application --> ActiveProfile

ActiveProfile --> DevConfig

ActiveProfile --> TestConfig

ActiveProfile --> ProdConfig

Each profile loads environment-specific properties.


Q9. How are Configuration Properties used in Kubernetes?

Production deployments often avoid bundling sensitive values inside the application.

Typical sources

  • ConfigMaps
  • Secrets
  • Environment Variables

Architecture

flowchart TD

ConfigMap --> SpringEnvironment

Secrets --> SpringEnvironment

EnvironmentVariables --> SpringEnvironment

SpringEnvironment --> Application

This approach enables the same application artifact to be deployed across multiple environments.


Q10. Configuration Best Practices

Use YAML for Large Projects

Hierarchical configuration is easier to maintain.


Prefer @ConfigurationProperties

Avoid excessive use of @Value.


Validate Configuration

Use Bean Validation annotations.


Never Store Secrets in Source Code

Use

  • Vault
  • Kubernetes Secrets
  • AWS Secrets Manager
  • Azure Key Vault

Banking Example

flowchart TD

application-prod.yml --> PaymentProperties

PaymentProperties --> PaymentService

application-prod.yml --> DatabaseProperties

DatabaseProperties --> DataSource

application-prod.yml --> KafkaProperties

KafkaProperties --> KafkaProducer

Configuration classes centralize environment-specific settings.


Common Interview Questions

  • What is Externalized Configuration?
  • application.properties vs application.yml?
  • What is @Value?
  • What is @ConfigurationProperties?
  • @Value vs @ConfigurationProperties?
  • How does property binding work?
  • How do you validate configuration?
  • What is property resolution order?
  • How are configurations managed in Kubernetes?
  • Configuration best practices?

Quick Revision

Topic Summary
Externalized Configuration Configuration outside code
application.properties Key-value format
application.yml Hierarchical YAML format
@Value Inject single property
@ConfigurationProperties Bind grouped properties
@Validated Validate configuration
Profiles Environment-specific configuration
Environment Variables Override properties
ConfigMaps Kubernetes configuration
Secrets Secure sensitive values

Configuration Loading Lifecycle

sequenceDiagram
Application->>SpringEnvironment: Start
SpringEnvironment->>Configuration Sources: Load Properties
Configuration Sources-->>SpringEnvironment: Values
SpringEnvironment->>Property Binder: Bind Properties
Property Binder->>ConfigurationProperties Bean: Populate Fields
ConfigurationProperties Bean-->>ApplicationContext: Ready
ApplicationContext-->>Application: Start

Production Example – Banking Microservice

A banking payment service is deployed to Development, UAT, and Production.

Configuration

  • application.yml contains common settings.
  • application-prod.yml overrides production-specific values.
  • Database passwords are supplied using Kubernetes Secrets.
  • Kafka broker addresses come from ConfigMaps.
  • Payment timeout and retry settings are bound using @ConfigurationProperties.
  • Validation ensures the application fails immediately if mandatory configuration is missing.
flowchart LR

application.yml --> SpringEnvironment

application-prod.yml --> SpringEnvironment

ConfigMap --> SpringEnvironment

KubernetesSecret --> SpringEnvironment

SpringEnvironment --> PaymentProperties

PaymentProperties --> PaymentService

The same application artifact is promoted across environments without code changes, improving deployment consistency and security.


Key Takeaways

  • Externalized Configuration separates application settings from application code, making deployments more flexible.
  • Spring Boot supports configuration from application.properties, application.yml, environment variables, command-line arguments, ConfigMaps, and cloud configuration services.
  • @ConfigurationProperties is the preferred approach for binding related configuration values because it is type-safe, maintainable, and supports validation.
  • @Value is suitable for injecting individual configuration values but is less appropriate for complex configuration objects.
  • Spring Boot resolves properties using a well-defined precedence order, allowing higher-priority sources to override lower-priority ones.
  • Use Profiles to manage environment-specific configurations without changing application code.
  • Validate configuration using Bean Validation annotations to detect configuration errors during startup.
  • Store sensitive information in secure external secret managers rather than directly in configuration files.