juniorSpring
What is the use of @Value annotation in Spring?
Updated May 17, 2026
Short answer
@Value injects values from properties files or environment variables into Spring beans.
Deep explanation
It allows externalized configuration injection into fields, constructors, or methods. Spring resolves placeholders like ${...} from application.properties or environment variables, enabling flexible configuration without code changes.
Real-world example
Injecting API keys or database URLs into services without hardcoding them.
Common mistakes
- Using @Value for complex configuration instead of @ConfigurationProperties.
Follow-up questions
- What is property placeholder resolution?
- When should @ConfigurationProperties be preferred?