Skip to main content

@PropertySource, @Value, Environment, EnvironmentPostProcessor, Externalized and Profile-Based Configuration

Learn @PropertySource, @Value, Environment, EnvironmentPostProcessor, Externalized and Profile-Based Configuration (Phase 4 · Spring Configuration (Core), Spring Core) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

@PropertySource, @Value and Environment • @PropertySource("classpath:app.properties") adds a properties file to the Environment (repeatable; ignoreResourceNotFound ; YAML needs a custom factory in plain Spring: Boot loads YAML natively). @Value("${key:default}") injects a property (resolved by a PropertySourcesPlaceholderConfigurer ; declare it as a static @Bean in plain Spring; Boot does it for you) and supports SpEL ( #{...} ). Environment gives programmatic access: getProperty(key, type, default) , getRequiredProperty , containsProperty , getActiveProfiles ,...

More lessons in Phase 4 · Spring Configuration (Core)