Class ResourcePropertySourceLoader

All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.annotation.ImportSelector, org.springframework.context.ApplicationContextAware, org.springframework.context.EnvironmentAware, org.springframework.context.ResourceLoaderAware

public class ResourcePropertySourceLoader extends PropertySourceExtensionLoader<ResourcePropertySource,PropertySourceExtensionAttributes<ResourcePropertySource>> implements org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean
Since:
1.0.0
Author:
Mercy
See Also:
  • Constructor Details

    • ResourcePropertySourceLoader

      public ResourcePropertySourceLoader()
  • Method Details

    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Initializes the ResourcePatternResolver and PathMatcher used for resolving resource patterns after all bean properties have been set.

      Example Usage

      
         // Typically invoked automatically by the Spring container:
         ResourcePropertySourceLoader loader = new ResourcePropertySourceLoader();
         loader.setResourceLoader(applicationContext);
         loader.afterPropertiesSet();
         // loader is now ready to resolve resource patterns like "classpath*:/META-INF/test/*.properties"
       
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception - if initialization fails
    • resolveResources

      protected org.springframework.core.io.Resource[] resolveResources(PropertySourceExtensionAttributes<ResourcePropertySource> extensionAttributes, String propertySourceName, String resourceValue) throws Throwable
      Resolves the Resource instances matching the given resource value pattern using the internal ResourcePatternResolver.

      Example Usage

      
         // Within a subclass or test:
         PropertySourceExtensionAttributes<ResourcePropertySource> attrs = ...;
         Resource[] resources = loader.resolveResources(attrs, "myPropertySource",
             "classpath*:/META-INF/test/*.properties");
         // resources contains all .properties files matching the pattern
       
      Specified by:
      resolveResources in class PropertySourceExtensionLoader<ResourcePropertySource,PropertySourceExtensionAttributes<ResourcePropertySource>>
      Parameters:
      extensionAttributes - the extension attributes of the ResourcePropertySource annotation
      propertySourceName - the name of the property source being loaded
      resourceValue - the resource location pattern to resolve (e.g. "classpath*:/META-INF/test/*.properties")
      Returns:
      an array of resolved Resource instances matching the pattern
      Throws:
      Throwable - if resource resolution fails
    • isResourcePattern

      public boolean isResourcePattern(String resourceValue)
      Determines whether the given resource value is a pattern containing wildcards (e.g. *, ?) that requires pattern-based resource resolution.

      Example Usage

      
         ResourcePropertySourceLoader loader = ...;
         boolean isPattern = loader.isResourcePattern("classpath*:/META-INF/test/*.properties"); // true
         boolean isNotPattern = loader.isResourcePattern("classpath:/META-INF/test/a.properties"); // false
       
      Specified by:
      isResourcePattern in class PropertySourceExtensionLoader<ResourcePropertySource,PropertySourceExtensionAttributes<ResourcePropertySource>>
      Parameters:
      resourceValue - the resource location string to test
      Returns:
      true if the resource value contains wildcard patterns, false otherwise
    • configureResourcePropertySourcesRefresher

      protected void configureResourcePropertySourcesRefresher(PropertySourceExtensionAttributes<ResourcePropertySource> extensionAttributes, List<PropertySourceExtensionLoader.PropertySourceResource> propertySourceResources, org.springframework.core.env.CompositePropertySource propertySource, PropertySourceExtensionLoader.ResourcePropertySourcesRefresher refresher) throws Throwable
      Configures the PropertySourceExtensionLoader.ResourcePropertySourcesRefresher by setting up a StandardFileWatchService that watches file-based resources for changes. When a watched file is created, modified, or deleted, the refresher is triggered to reload the affected property sources.

      Example Usage

      
         // Called internally by the property source loading lifecycle when autoRefreshed = true.
         // For example, given the annotation:
         // @ResourcePropertySource(value = "classpath*:/META-INF/test/*.properties", autoRefreshed = true)
         // the loader internally invokes this method to set up file watching on the resolved
         // .properties files, so that property sources are refreshed when files change on disk.
       
      Overrides:
      configureResourcePropertySourcesRefresher in class PropertySourceExtensionLoader<ResourcePropertySource,PropertySourceExtensionAttributes<ResourcePropertySource>>
      Parameters:
      extensionAttributes - the extension attributes of the ResourcePropertySource annotation
      propertySourceResources - the list of property source resources to watch
      propertySource - the composite property source that aggregates the individual sources
      refresher - the refresher to invoke when file changes are detected
      Throws:
      Throwable - if configuring the file watch service fails
    • destroy

      public void destroy() throws Exception
      Stops the internal StandardFileWatchService if it was started, releasing file watching resources.

      Example Usage

      
         // Typically invoked automatically by the Spring container on shutdown:
         ResourcePropertySourceLoader loader = ...;
         loader.destroy();
         // The file watch service is stopped and resources are released
       
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean
      Throws:
      Exception - if stopping the file watch service fails