ConfigurationProperties vs PropertySource vs Value
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
@Value, @PropertySource, and @ConfigurationProperties are related to configuration in Spring, but they operate at different layers. One injects individual values, one adds a source of properties, and one binds a structured group of properties into a typed object.
@Value Injects Individual Properties
Use @Value when you need one or two standalone values inside a bean.
This is concise, but it becomes messy when many related settings are scattered across several fields or classes.
@PropertySource Adds Another Property Source
@PropertySource does not inject values by itself. Its job is to load an extra properties file into the Spring environment.
After this, other mechanisms such as @Value or @ConfigurationProperties can read from that source.
That is the core distinction: @PropertySource changes where properties come from, not how they are bound into objects.
@ConfigurationProperties Binds Related Settings as a Group
For structured configuration, @ConfigurationProperties is usually the cleaner option.
Then register it as a bean:
This approach scales better because the configuration is typed, grouped, and easier to validate.
When to Choose Each One
A practical rule is:
- use
@Valuefor a very small number of simple values - use
@PropertySourcewhen you need to add another property file - use
@ConfigurationPropertiesfor grouped application settings
These annotations are not real substitutes for one another. They solve different parts of the configuration story.
Why @ConfigurationProperties Usually Wins for Real Applications
Large applications often have grouped settings such as mail.*, storage.*, or feature.*. Injecting each field separately with @Value spreads string keys throughout the codebase and makes testing harder.
A properties class keeps that configuration cohesive. It also makes it easier to add validation, constructor injection, and clearer documentation of what the application expects.
In other words, @ConfigurationProperties treats configuration as structured data instead of as scattered string lookups.
A major reason teams prefer @ConfigurationProperties is validation. Once configuration is grouped into a typed class, you can validate it as one coherent unit instead of discovering missing or malformed values later through scattered failures.
Configuration precedence also becomes easier to understand when property sources and binding are treated separately. Once those responsibilities are mixed mentally, it becomes much harder to explain why a particular value won or where it actually came from.
Common Pitfalls
Treating @PropertySource as though it binds values directly is a conceptual mistake.
Overusing @Value for large groups of settings leads to scattered configuration and duplicated property keys.
Defining a @ConfigurationProperties class without registering or scanning it leaves you with a type that never actually binds.
Summary
- '
@Valueinjects individual property values.' - '
@PropertySourceadds an additional property source to the environment.' - '
@ConfigurationPropertiesbinds a related group of settings into a typed object.' - For larger, structured configuration,
@ConfigurationPropertiesis usually the best long-term choice.

