Annotation Type PropertySourceExtension
-
@Target(ANNOTATION_TYPE) @Retention(RUNTIME) @Inherited @Documented public @interface PropertySourceExtension
Extension meta-annotation for Spring's@PropertySource
to overcome its limitations:- The
@PropertySource
annotation can't auto-refresh theproperty sources
- The
@PropertySource
annotation can't control the order ofPropertySource
- The
@PropertySource
annotation can't beinherited
- The
PropertySource#value()
attribute does not support theresource
location wildcards - The
PropertySource#encoding()
attribute does not specify the default encoding for theresource
Features:
- Supports auto-refreshing property sources when configurations change
- Allows specifying the order of property sources using:
- Supports inheritance via the
@Inherited
annotation - Resource location wildcards are supported in the
value()
attribute - Provides control over resource loading behavior with:
- Customizable property source creation via the
factory()
attribute
Example Usage
Basic Usage
{@code // Define a custom annotation using PropertySourceExtension
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
PropertySource
,ResourcePropertySource
,PropertySource
,PropertySourceExtensionLoader
- The
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description java.lang.String
after
The relative order after specifiedPropertySource
boolean
autoRefreshed
It indicates the property source is auto-refreshed when the configuration is changed.java.lang.String
before
The relative order before specifiedPropertySource
java.lang.String
encoding
A specific character encoding for the given resources.java.lang.Class<? extends org.springframework.core.io.support.PropertySourceFactory>
factory
Specify a customPropertySourceFactory
, if any.boolean
first
boolean
ignoreResourceNotFound
Indicate if a failure to find aproperty resource
should be ignored.java.lang.String
name
Indicate the name of this property source.java.lang.Class<? extends java.util.Comparator<org.springframework.core.io.Resource>>
resourceComparator
Indicate the resources to be sorted whenvalue()
specifies the resource location wildcards or the same resource names with the different absolute paths.java.lang.String[]
value
Indicate the resource(s) of the property source to be loaded.
-
-
-
-
before
java.lang.String before
The relative order before specifiedPropertySource
If not specified , current
PropertySource
will be added last.If
first()
specified , current attribute will be ignored.- Returns:
- the name of
PropertySource
, default value is the empty string
- Default:
- ""
-
-
-
after
java.lang.String after
The relative order after specifiedPropertySource
If not specified , current
PropertySource
will be added last.If
first()
specified , current attribute will be ignored.- Returns:
- the name of
PropertySource
, default value is the empty string
- Default:
- ""
-
-
-
value
java.lang.String[] value
Indicate the resource(s) of the property source to be loaded.For example,
"classpath:/com/myco/app.properties"
or"file:/path/to/file.xml"
.Resource wildcards (e.g. **/*.properties) also are permitted;
${...} placeholders will be resolved against any/all property sources already registered with the
Environment
.Each value will be added to the enclosing
Environment
as its own property source, and in the order declared.- Default:
- {}
-
-
-
resourceComparator
java.lang.Class<? extends java.util.Comparator<org.springframework.core.io.Resource>> resourceComparator
Indicate the resources to be sorted whenvalue()
specifies the resource location wildcards or the same resource names with the different absolute paths.For example,
"classpath:/com/myco/*.properties"
, suppose there are two resources named "a.properties" and "b.properties" where two instances ofResource
will be resolved, they are the sources ofPropertySource
, thus it has to sort them to indicate the order ofPropertySource
that will be added to the enclosingEnvironment
.Default is
DefaultResourceComparator
- See Also:
DefaultResourceComparator
- Default:
- io.microsphere.spring.config.env.support.DefaultResourceComparator.class
-
-
-
ignoreResourceNotFound
boolean ignoreResourceNotFound
Indicate if a failure to find aproperty resource
should be ignored.true
is appropriate if the properties file is completely optional.Default is
false
.- Default:
- false
-
-
-
factory
java.lang.Class<? extends org.springframework.core.io.support.PropertySourceFactory> factory
Specify a customPropertySourceFactory
, if any.By default, a default factory for standard resource files will be used.
Default is
DefaultPropertySourceFactory
- See Also:
DefaultPropertySourceFactory
,ResourcePropertySource
- Default:
- org.springframework.core.io.support.DefaultPropertySourceFactory.class
-
-