@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 ClassesModifier and TypeClassDescriptionstatic interfaceExtension ofConfigused to signal that no specific configuration type has been configured. -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionThe bean name of the configuration to use as property source.booleanWhether to ignore if no bean of the specified type or name is found.The type of the configuration to use as property source.The bean name of the configuration to use as property source. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe prefix for the names of the property sources.
-
Field Details
-
SOURCE_PREFIX
The prefix for the names of the property sources.- See Also:
-
-
Element Details
-
value
String valueThe bean name of the configuration to use as property source.Alias for
name().- Returns:
- The configuration type.
- Default:
- ""
-
name
String nameThe bean name of the configuration to use as property source.- Returns:
- The configuration bean name.
- Default:
- ""
-
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 optionalWhether 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
-