Class ConfigPropertySourcePostProcessor

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

    Fields
    Modifier and Type
    Field
    Description
    protected org.springframework.core.env.ConfigurableEnvironment
    The Spring environment.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected String
    findBeanByType(@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.
    void
    postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
    protected void
    processAggregateAnnotations(@NotNull org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, @NotNull String configurationBean, @NotNull org.springframework.core.type.AnnotationMetadata annotations)
    Process aggregated @ConfigPropertySources annotations on the given class and add the corresponding property sources to the environment.
    protected void
    processConfigurationBean(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, String configurationBean, org.springframework.core.type.AnnotationMetadata annotations)
    Process the @ConfigPropertySource annotations on the given configuration bean and add the corresponding property sources to the environment.
    protected void
    processSingleAnnotations(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, String configurationBean, org.springframework.core.type.AnnotationMetadata annotations)
    Process single @ConfigPropertySource annotations on the given class and add the corresponding property sources to the environment.
    protected void
    processSource(@NotNull org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, @NotNull String configurationBean, @NotNull org.springframework.core.annotation.AnnotationAttributes annotation)
    Process a single @ConfigPropertySource annotation and add the corresponding property source to the environment.
    void
    setEnvironment(@NotNull org.springframework.core.env.Environment environment)
    protected String
    validateConfigName(@NotNull org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, @NotNull String configName, boolean ignoreMissing)
    Validates the the specified bean name corresponds to a Config bean, and returns the name if valid.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • environment

      protected org.springframework.core.env.ConfigurableEnvironment environment
      The 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:
      setEnvironment in interface org.springframework.context.EnvironmentAware
    • postProcessBeanFactory

      public void postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) throws org.springframework.beans.BeansException
      Specified by:
      postProcessBeanFactory in interface org.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 @ConfigPropertySource annotations 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 - The Configuration bean annotation metadata to process.
      Throws:
      org.springframework.beans.factory.BeanInitializationException - If the configuration bean cannot be found and optional is false, 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 @ConfigPropertySource annotations 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 - The Configuration bean annotation metadata.
      Throws:
      org.springframework.beans.factory.BeanInitializationException - If the configuration bean cannot be found and optional is false, 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 @ConfigPropertySources annotations 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 - The Configuration bean annotation metadata.
      Throws:
      org.springframework.beans.factory.BeanInitializationException - If the configuration bean cannot be found and optional is false, 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 @ConfigPropertySource annotation 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 - The ConfigPropertySource annotation data to process.
      Throws:
      org.springframework.beans.factory.BeanInitializationException - If the configuration bean cannot be found and optional is false, 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 a Config bean, 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 null if not found and ignoreMissing is true.
      Throws:
      org.springframework.beans.factory.BeanInitializationException - If no configuration bean is found and ignoreMissing is false.
    • 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 null if not found and ignoreMissing is true.
      Throws:
      org.springframework.beans.factory.BeanInitializationException - If multiple configuration beans of the specified type are found, or if no configuration bean is found and ignoreMissing is false.