Annotation Interface DefaultPropertiesPropertySource


@Target(TYPE) @Retention(RUNTIME) @Inherited @Documented @Repeatable(DefaultPropertiesPropertySources.class) @Import(io.microsphere.spring.config.context.annotation.DefaultPropertiesPropertySourceLoader.class) public @interface DefaultPropertiesPropertySource
A variant of the @PropertySource annotation for the PropertySource named "defaultProperties".

Annotation providing a convenient and declarative mechanism for adding a PropertySource to Spring's Environment. To be used in conjunction with @Configuration classes.

Example Usage

 
 @Configuration
 @DefaultPropertiesPropertySource("classpath:com/myco/app.properties")
 public class MyConfig {
 }
 
 

Multiple Locations Example:

 
 @Configuration
 @DefaultPropertiesPropertySource(value = {
     "classpath:com/myco/app1.properties",
     "file:/path/to/app2.properties"
 })
 public class MyConfig {
 }
 
 

Wildcard Usage Example:

 
 @Configuration
 @DefaultPropertiesPropertySource("classpath*:com/myco/*.properties")
 public class MyConfig {
 }
 
 
Since:
1.0.0
Author:
Mercy
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    A specific character encoding for the given resources.
    Class<? extends org.springframework.core.io.support.PropertySourceFactory>
    Specify a custom PropertySourceFactory, if any.
    boolean
    Indicate if a failure to find a property resource should be ignored.
    Class<? extends Comparator<org.springframework.core.io.Resource>>
    Indicate the resources to be sorted when value() specifies the resource location wildcards or the same resource names with the different absolute paths.
    Indicate the resource location(s) of the property source file to be loaded.
  • Element Details

    • value

      String[] value
      Indicate the resource location(s) of the property source file to be loaded.

      Both traditional and XML-based properties file formats are supported — for example, "classpath:/com/myco/app.properties" or "file:/path/to/file.xml".

      Resource location wildcards (e.g. **/*.properties) also are permitted;

      ${...} placeholders will be resolved against any/all property sources already registered with the Environment.

      Each location will be added to the enclosing Environment as its own property source, and in the order declared.

      Default:
      {}
    • resourceComparator

      Class<? extends Comparator<org.springframework.core.io.Resource>> resourceComparator
      Indicate the resources to be sorted when value() 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 of Resource will be resolved, they are the sources of PropertySource, thus it has to sort them to indicate the order of PropertySource that will be added to the enclosing Environment.

      Default is DefaultResourceComparator

      See Also:
      Default:
      io.microsphere.spring.config.env.support.DefaultResourceComparator.class
    • ignoreResourceNotFound

      boolean ignoreResourceNotFound
      Indicate if a failure to find a property resource should be ignored.

      true is appropriate if the properties file is completely optional.

      Default is false.

      Default:
      false
    • encoding

      String encoding
      A specific character encoding for the given resources.

      Default is "UTF-8"

      Default:
      "UTF-8"
    • factory

      Class<? extends org.springframework.core.io.support.PropertySourceFactory> factory
      Specify a custom PropertySourceFactory, 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