Skip to content

io microsphere spring config context annotation ResourcePropertySourceLoader

github-actions[bot] edited this page Jul 11, 2026 · 25 revisions

ResourcePropertySourceLoader

Type: Class | Module: microsphere-spring-context | Package: io.microsphere.spring.config.context.annotation | Since: 1.0.0

Source: microsphere-spring-context/src/main/java/io/microsphere/spring/config/context/annotation/ResourcePropertySourceLoader.java

Overview

The PropertySourceExtensionLoader Class for ResourcePropertySource

Declaration

public class ResourcePropertySourceLoader extends PropertySourceExtensionLoader<ResourcePropertySource,

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.2.36-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

Method Examples

afterPropertiesSet

// 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"

isResourcePattern

// 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
ResourcePropertySourceLoader loader = ...;
  boolean isPattern = loader.isResourcePattern("classpath*:/META-INF/test/*.properties"); // true
  boolean isNotPattern = loader.isResourcePattern("classpath:/META-INF/test/a.properties"); // false

register

// 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.
ListenerAdapter adapter = new ListenerAdapter(refresher, 4);
  File propertiesFile = new File("/META-INF/test/a.properties");
  adapter.register(propertiesFile, "classpath*:/META-INF/test/*.properties");

onFileCreated

// Automatically invoked by the file watch service when a new file is detected:
  // e.g., creating "c.properties" in a watched directory triggers a refresh
  // if it matches a registered pattern like "classpath*:/META-INF/test/*.properties"

onFileModified

// Automatically invoked by the file watch service when a tracked file is modified:
  // e.g., modifying "b.properties" triggers a refresh of its associated property source

onFileDeleted

// Automatically invoked by the file watch service when a tracked file is deleted:
  // e.g., deleting "a.properties" triggers a refresh and removed properties are reported

destroy

// Typically invoked automatically by the Spring container on shutdown:
  ResourcePropertySourceLoader loader = ...;
  loader.destroy();
  // The file watch service is stopped and resources are released

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-spring-context</artifactId>
    <version>${microsphere-spring.version}</version>
</dependency>

Tip: Use the BOM (microsphere-spring-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.spring.config.context.annotation.ResourcePropertySourceLoader;

API Reference

Public Methods

Method Description
afterPropertiesSet Initializes the ResourcePatternResolver and PathMatcher used for resolving
isResourcePattern Resolves the Resource instances matching the given resource value pattern
register Configures the ResourcePropertySourcesRefresher by setting up a
onFileCreated Handles a file creation event by checking if the newly created file matches any
onFileModified Handles a file modification event by refreshing the property source associated with
onFileDeleted Handles a file deletion event by delegating to #onFileModified(FileChangedEvent),
destroy Stops the internal StandardFileWatchService if it was started,

Method Details

afterPropertiesSet

public void afterPropertiesSet()

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"
`

isResourcePattern

public boolean isResourcePattern(String resourceValue)

Resolves the Resource instances matching the given resource value pattern using the internal ResourcePatternResolver.

Example Usage

`// Within a subclass or test:
  PropertySourceExtensionAttributes attrs = ...;
  Resource[] resources = loader.resolveResources(attrs, "myPropertySource",
      "classpath*:/META-INF/test/*.properties");
  // resources contains all .properties files matching the pattern
`

register

public void register(File file, String resourceValue)

Configures the 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.
`

onFileCreated

public void onFileCreated(FileChangedEvent event)

Handles a file creation event by checking if the newly created file matches any registered resource patterns and triggering a property source refresh if so.

Example Usage

`// Automatically invoked by the file watch service when a new file is detected:
  // e.g., creating "c.properties" in a watched directory triggers a refresh
  // if it matches a registered pattern like "classpath*:/META-INF/test/*.properties"
`

onFileModified

public void onFileModified(FileChangedEvent event)

Handles a file modification event by refreshing the property source associated with the modified file.

Example Usage

`// Automatically invoked by the file watch service when a tracked file is modified:
  // e.g., modifying "b.properties" triggers a refresh of its associated property source
`

onFileDeleted

public void onFileDeleted(FileChangedEvent event)

Handles a file deletion event by delegating to #onFileModified(FileChangedEvent), which triggers a refresh of the property source associated with the deleted file.

Example Usage

`// Automatically invoked by the file watch service when a tracked file is deleted:
  // e.g., deleting "a.properties" triggers a refresh and removed properties are reported
`

destroy

public void destroy()

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
`

See Also

  • ResourcePropertySource
  • PropertySourceExtensionAttributes

This documentation was auto-generated from the source code of microsphere-spring.

Home

spring-context

spring-guice

spring-jdbc

spring-test

spring-web

spring-webflux

spring-webmvc

Clone this wiki locally