Spring / Spring7 basics Interview questions
What is the purpose of a PropertySource in Spring?
A PropertySource represents a single origin of key-value configuration - a .properties file, a .yml file, environment variables, or command-line arguments - that Spring's Environment abstraction merges together into one searchable set of properties.
@Configuration @PropertySource("classpath:mail.properties") public class MailConfig { @Value("${mail.host}") private String host; }
When several sources define the same key, Spring resolves it using a defined precedence order - command-line arguments and environment variables typically outrank values in application.properties. This layered model is what lets the exact same code read different settings in development, testing, and production without any code changes.
More Related questions...