Annotation Interface ConfigPropertySource


@Documented @Retention(RUNTIME) @Target(TYPE) @Repeatable(ConfigPropertySources.class) @Import(ConfigPropertySourcePostProcessor.class) @API(status=STABLE, since="1.0") public @interface ConfigPropertySource
Annotation that adds a PropertySource to Spring's Environment that will use the specified Config context bean.

Example:

 @Configuration
 @ConfigPropertySource("myConfig")
 public class AppConfig {
    // ...
    @Bean
    public Config myConfig() {
        // ...
    }
    // ...
 }
 // Environment.getProperty() will now resolve properties from "myConfig" Config bean.
 

NOTE: This annotation is repeatable according to Java 8 conventions.

Since:
1.0
Version:
1.0, 2025-08
Author:
(w) Iker Hernaez
See Also:
  • PropertySource
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Extension of Config used to signal that no specific configuration type has been configured.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The bean name of the configuration to use as property source.
    boolean
    Whether to ignore if no bean of the specified type or name is found.
    Class<? extends Config>
    The type of the configuration to use as property source.
    The bean name of the configuration to use as property source.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The prefix for the names of the property sources.
  • Field Details

  • Element Details

    • value

      String value
      The bean name of the configuration to use as property source.

      Alias for name().

      Returns:
      The configuration type.
      Default:
      ""
    • name

      String name
      The bean name of the configuration to use as property source.
      Returns:
      The configuration bean name.
      Default:
      ""
    • type

      Class<? extends Config> type
      The type of the configuration to use as property source.
      Returns:
      The configuration type.
      Default:
      dev.orne.config.spring.ConfigPropertySource.Unconfigured.class
    • optional

      boolean optional
      Whether to ignore if no bean of the specified type or name is found.

      If set to true, and no matching bean is found, the property source will not be added to the environment, but no error will be raised.

      Default is false, which will raise an exception if no matching bean is found.

      Returns:
      Whether to ignore if no matching bean is found.
      Default:
      false