java.lang.Object
dev.orne.config.spring.ConfigPropertySourcePostProcessor
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.config.BeanFactoryPostProcessor,org.springframework.context.EnvironmentAware
@API(status=INTERNAL,
since="1.0")
public class ConfigPropertySourcePostProcessor
extends Object
implements org.springframework.context.EnvironmentAware, org.springframework.beans.factory.config.BeanFactoryPostProcessor
Spring bean factory post processor that adds to the Spring environment
the property sources defined by
@ConfigPropertySource annotations
on @Configuration beans.- Since:
- 1.0
- Version:
- 1.0, 2025-08
- Author:
- (w) Iker Hernaez
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.springframework.core.env.ConfigurableEnvironmentThe Spring environment. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringfindBeanByType(@NotNull org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, @NotNull Class<? extends Config> configType, boolean ignoreMissing) Finds a unique bean of the specified configuration type, and returns its name.voidpostProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) protected voidprocessAggregateAnnotations(@NotNull org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, @NotNull String configurationBean, @NotNull org.springframework.core.type.AnnotationMetadata annotations) Process aggregated@ConfigPropertySourcesannotations on the given class and add the corresponding property sources to the environment.protected voidprocessConfigurationBean(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, String configurationBean, org.springframework.core.type.AnnotationMetadata annotations) Process the@ConfigPropertySourceannotations on the given configuration bean and add the corresponding property sources to the environment.protected voidprocessSingleAnnotations(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, String configurationBean, org.springframework.core.type.AnnotationMetadata annotations) Process single@ConfigPropertySourceannotations on the given class and add the corresponding property sources to the environment.protected voidprocessSource(@NotNull org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, @NotNull String configurationBean, @NotNull org.springframework.core.annotation.AnnotationAttributes annotation) Process a single@ConfigPropertySourceannotation and add the corresponding property source to the environment.voidsetEnvironment(@NotNull org.springframework.core.env.Environment environment) protected StringvalidateConfigName(@NotNull org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, @NotNull String configName, boolean ignoreMissing) Validates the the specified bean name corresponds to aConfigbean, and returns the name if valid.
-
Field Details
-
environment
protected org.springframework.core.env.ConfigurableEnvironment environmentThe Spring environment.
-
-
Constructor Details
-
ConfigPropertySourcePostProcessor
public ConfigPropertySourcePostProcessor()Creates a new instance.
-
-
Method Details
-
setEnvironment
public void setEnvironment(@NotNull @NotNull org.springframework.core.env.Environment environment) - Specified by:
setEnvironmentin interfaceorg.springframework.context.EnvironmentAware
-
postProcessBeanFactory
public void postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) throws org.springframework.beans.BeansException - Specified by:
postProcessBeanFactoryin interfaceorg.springframework.beans.factory.config.BeanFactoryPostProcessor- Throws:
org.springframework.beans.BeansException
-
processConfigurationBean
protected void processConfigurationBean(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, String configurationBean, org.springframework.core.type.AnnotationMetadata annotations) Process the@ConfigPropertySourceannotations on the given configuration bean and add the corresponding property sources to the environment.- Parameters:
beanFactory- The bean factory to retrieve configuration beans from.configurationBean- The name of the configuration bean.annotations- TheConfigurationbean annotation metadata to process.- Throws:
org.springframework.beans.factory.BeanInitializationException- If the configuration bean cannot be found andoptionalisfalse, or if multiple configuration beans of the specified type are found.
-
processSingleAnnotations
protected void processSingleAnnotations(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, String configurationBean, org.springframework.core.type.AnnotationMetadata annotations) Process single@ConfigPropertySourceannotations on the given class and add the corresponding property sources to the environment.- Parameters:
beanFactory- The bean factory to retrieve configuration beans from.configurationBean- The name of the configuration bean.annotations- TheConfigurationbean annotation metadata.- Throws:
org.springframework.beans.factory.BeanInitializationException- If the configuration bean cannot be found andoptionalisfalse, or if multiple configuration beans of the specified type are found.
-
processAggregateAnnotations
protected void processAggregateAnnotations(@NotNull @NotNull org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, @NotNull @NotNull String configurationBean, @NotNull @NotNull org.springframework.core.type.AnnotationMetadata annotations) Process aggregated@ConfigPropertySourcesannotations on the given class and add the corresponding property sources to the environment.- Parameters:
beanFactory- The bean factory to retrieve configuration beans from.configurationBean- The name of the configuration bean.annotations- TheConfigurationbean annotation metadata.- Throws:
org.springframework.beans.factory.BeanInitializationException- If the configuration bean cannot be found andoptionalisfalse, or if multiple configuration beans of the specified type are found.
-
processSource
protected void processSource(@NotNull @NotNull org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, @NotNull @NotNull String configurationBean, @NotNull @NotNull org.springframework.core.annotation.AnnotationAttributes annotation) Process a single@ConfigPropertySourceannotation and add the corresponding property source to the environment.- Parameters:
beanFactory- The bean factory to retrieve configuration beans from.configurationBean- The name of the configuration bean.annotation- TheConfigPropertySourceannotation data to process.- Throws:
org.springframework.beans.factory.BeanInitializationException- If the configuration bean cannot be found andoptionalisfalse, or if multiple configuration beans of the specified type are found.
-
validateConfigName
protected String validateConfigName(@NotNull @NotNull org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, @NotNull @NotNull String configName, boolean ignoreMissing) Validates the the specified bean name corresponds to aConfigbean, and returns the name if valid.- Parameters:
beanFactory- The bean factory to retrieve configuration beans from.configName- The name of the configuration bean.ignoreMissing- Whether to ignore a missing configuration bean.- Returns:
- The configuration bean name, or
nullif not found andignoreMissingistrue. - Throws:
org.springframework.beans.factory.BeanInitializationException- If no configuration bean is found andignoreMissingisfalse.
-
findBeanByType
protected String findBeanByType(@NotNull @NotNull org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, @NotNull @NotNull Class<? extends Config> configType, boolean ignoreMissing) Finds a unique bean of the specified configuration type, and returns its name.Does consider prototypes and objects created by FactoryBeans, which means that FactoryBeans will get initialized. If the object created by the FactoryBean doesn't match, the raw FactoryBean itself will be matched against the type.
- Parameters:
beanFactory- The bean factory to retrieve configuration beans from.configType- The type of the configuration bean.ignoreMissing- Whether to ignore a missing configuration bean.- Returns:
- The configuration bean name, or
nullif not found andignoreMissingistrue. - Throws:
org.springframework.beans.factory.BeanInitializationException- If multiple configuration beans of the specified type are found, or if no configuration bean is found andignoreMissingisfalse.
-