-
Notifications
You must be signed in to change notification settings - Fork 39
io microsphere spring config context annotation ResourcePropertySourceLoader
Type: Class | Module: microsphere-spring-context | Package: io.microsphere.spring.config.context.annotation | Since: 1.0.0
The PropertySourceExtensionLoader Class for ResourcePropertySource
public class ResourcePropertySourceLoader extends PropertySourceExtensionLoader<ResourcePropertySource,Author: Mercy
-
Introduced in:
1.0.0 -
Current Project Version:
0.2.36-SNAPSHOT
This component is tested and compatible with the following Java versions:
| Java Version | Status |
|---|---|
| Java 17 | ✅ Compatible |
| Java 21 | ✅ Compatible |
| Java 25 | ✅ Compatible |
// 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"// 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 patternResourcePropertySourceLoader loader = ...;
boolean isPattern = loader.isResourcePattern("classpath*:/META-INF/test/*.properties"); // true
boolean isNotPattern = loader.isResourcePattern("classpath:/META-INF/test/a.properties"); // false// 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");// 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"// 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// 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// Typically invoked automatically by the Spring container on shutdown:
ResourcePropertySourceLoader loader = ...;
loader.destroy();
// The file watch service is stopped and resources are releasedAdd 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 io.microsphere.spring.config.context.annotation.ResourcePropertySourceLoader;| 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, |
public void afterPropertiesSet()Initializes the ResourcePatternResolver and PathMatcher used for resolving
resource patterns after all bean properties have been set.
`// 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" `
public boolean isResourcePattern(String resourceValue)Resolves the Resource instances matching the given resource value pattern
using the internal ResourcePatternResolver.
`// 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
`
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.
`// 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. `
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.
`// 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" `
public void onFileModified(FileChangedEvent event)Handles a file modification event by refreshing the property source associated with the modified file.
`// 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 `
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.
`// 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 `
public void destroy()Stops the internal StandardFileWatchService if it was started,
releasing file watching resources.
`// Typically invoked automatically by the Spring container on shutdown: ResourcePropertySourceLoader loader = ...; loader.destroy(); // The file watch service is stopped and resources are released `
ResourcePropertySourcePropertySourceExtensionAttributes
This documentation was auto-generated from the source code of microsphere-spring.
spring-context
- AbstractInjectionPointDependencyResolver
- AbstractSmartLifecycle
- AbstractSpringResourceURLConnection
- AnnotatedBeanCapableImportBeanDefinitionRegistrar
- AnnotatedBeanCapableImportCandidate
- AnnotatedBeanCapableImportSelector
- AnnotatedBeanDefinitionRegistryUtils
- AnnotatedInjectionBeanPostProcessor
- AnnotatedInjectionPointDependencyResolver
- AnnotatedPropertySourceLoader
- AnnotationBeanDefinitionRegistryPostProcessor
- AnnotationUtils
- ApplicationContextUtils
- ApplicationEventInterceptor
- ApplicationEventInterceptorChain
- ApplicationListenerInterceptor
- ApplicationListenerInterceptorChain
- AutoRegistrationBean
- AutoRegistrationBeanInitializer
- AutoRegistrationBeanRegistrar
- AutowireCandidateResolvingListener
- AutowiredInjectionPointDependencyResolver
- BeanCapableImportCandidate
- BeanDefinitionUtils
- BeanDependencyResolver
- BeanFactoryListener
- BeanFactoryListenerAdapter
- BeanFactoryListeners
- BeanFactoryUtils
- BeanListener
- BeanListenerAdapter
- BeanListeners
- BeanMethodInjectionPointDependencyResolver
- BeanPropertyChangedEvent
- BeanRegistrar
- BeanSource
- BeanTimeStatistics
- BeanUtils
- CollectingConfigurationPropertyListener
- CompositeAutowireCandidateResolvingListener
- ConfigurableApplicationContextInitializer
- ConfigurationBeanAliasGenerator
- ConfigurationBeanBinder
- ConfigurationBeanBindingPostProcessor
- ConfigurationBeanBindingRegistrar
- ConfigurationBeanBindingsRegister
- ConfigurationBeanCustomizer
- ConfigurationPropertyOverrideAnnotationAttributesStrategy
- ConfigurationPropertyRepository
- ConstructionInjectionPointDependencyResolver
- ConversionServiceResolver
- ConversionServiceUtils
- DefaultApplicationEventInterceptorChain
- DefaultApplicationListenerInterceptorChain
- DefaultBeanDependencyResolver
- DefaultConfigurationBeanAliasGenerator
- DefaultConfigurationBeanBinder
- DefaultPropertiesPropertySource
- DefaultPropertiesPropertySourceLoader
- DefaultPropertiesPropertySources
- DefaultPropertiesPropertySourcesLoader
- DefaultResourceComparator
- DelegatingFactoryBean
- Dependency
- DependencyAnalysisBeanFactoryListener
- DependencyTreeWalker
- EnableAutoRegistrationBean
- EnableConfigurationBeanBinding
- EnableConfigurationBeanBindings
- EnableEventExtension
- EnableSpringConverterAdapter
- EnableSpringConverterAdapterRegistrar
- EnableTTLCaching
- EnvironmentEnabled
- EnvironmentListener
- EnvironmentUtils
- EventExtensionAttributes
- EventExtensionRegistrar
- EventPublishingBeanAfterProcessor
- EventPublishingBeanBeforeProcessor
- EventPublishingBeanInitializer
- ExposingClassPathBeanDefinitionScanner
- FilterMode
- GenericAnnotationAttributes
- GenericApplicationListenerAdapter
- GenericBeanNameGenerator
- GenericBeanPostProcessorAdapter
- HyphenAliasGenerator
- ImmutableMapPropertySource
- ImportOptional
- ImportOptionalSelector
- InjectionPointDependencyResolver
- InjectionPointDependencyResolvers
- InterceptingApplicationEventMulticaster
- InterceptingApplicationEventMulticasterProxy
- InterceptingApplicationListener
- JavaBeansPropertyChangeListenerAdapter
- JoinAliasGenerator
- JsonPropertySource
- JsonPropertySourceFactory
- ListenableAutowireCandidateResolver
- ListenableAutowireCandidateResolverInitializer
- ListenableConfigurableEnvironment
- ListenableConfigurableEnvironmentInitializer
- LoggingAutowireCandidateResolvingListener
- LoggingBeanFactoryListener
- LoggingBeanListener
- LoggingEnvironmentListener
- LoggingSmartLifecycle
- MethodParameterUtils
- MimeTypeUtils
- NamedBeanHolderComparator
- OnceApplicationContextEventListener
- OverrideAnnotationAttributes
- OverrideAnnotationAttributesStrategy
- ParallelPreInstantiationSingletonsBeanFactoryListener
- ProfileListener
- PropertiesUtils
- PropertyConstants
- PropertyResolverListener
- PropertyResolverUtils
- PropertySourceChangedEvent
- PropertySourceExtension
- PropertySourceExtensionAttributes
- PropertySourceExtensionLoader
- PropertySourcesChangedEvent
- PropertySourcesUtils
- PropertyValuesUtils
- ResolvableDependencyTypeFilter
- ResolvablePlaceholderAnnotationAttributes
- ResourceInjectionPointDependencyResolver
- ResourceLoaderUtils
- ResourcePropertySource
- ResourcePropertySourceLoader
- ResourcePropertySources
- ResourcePropertySourcesLoader
- ResourceUtils
- ResourceYamlProcessor
- SpringConverterAdapter
- SpringDelegatingBeanProtocolURLConnectionFactory
- SpringEnvironmentURLConnectionFactory
- SpringFactoriesLoaderUtils
- SpringProfilesURLConnectionAdapter
- SpringPropertySourcesURLConnectionAdapter
- SpringProtocolURLStreamHandler
- SpringResourceURLConnection
- SpringResourceURLConnectionAdapter
- SpringResourceURLConnectionFactory
- SpringSubProtocolURLConnectionFactory
- SpringVersion
- SpringVersionUtils
- TTLCachePut
- TTLCacheResolver
- TTLCacheable
- TTLCachingConfiguration
- TTLContext
- UnderScoreJoinAliasGenerator
- YamlPropertySource
- YamlPropertySourceFactory
spring-guice
spring-jdbc
- CompoundJdbcEventListenerFactory
- EnableP6DataSource
- NoOpP6LoadableOptions
- P6DataSourceBeanDefinitionRegistrar
- P6DataSourceBeanPostProcessor
- PropertySourcesP6LoadableOptionsAdapter
- SpringP6SpyURLConnectionFactory
spring-test
- AbstractWebFluxTest
- AbstractWebMvcTest
- AnnotatedTypeMetadataTestFactory
- EmbeddedDataBaseBeanDefinitionRegistrar
- EmbeddedDataBaseBeanDefinitionsRegistrar
- EmbeddedDatabaseType
- EmbeddedTomcatConfiguration
- EmbeddedTomcatContextLoader
- EmbeddedTomcatMergedContextConfiguration
- EmbeddedTomcatTestContextBootstrapper
- EmbeddedZookeeperServer
- EmbeddedZookeeperServerTestExecutionListener
- EnableEmbeddedDatabase
- EnableEmbeddedDatabases
- MockServletWebRequest
- PersonHandler
- PersonHandler
- RouterFunctionTestConfig
- RouterFunctionTestConfig
- ServletTestUtils
- SimpleUrlHandlerMappingTestConfig
- SimpleUrlHandlerMappingTestConfig
- SpringLoggingTest
- SpringTestUtils
- SpringTestWebUtils
- TestConditionContext
- TestController
- TestFilter
- TestFilterRegistration
- TestServlet
- TestServletContext
- TestServletContextListener
- TestServletRegistration
- User
- WebTestUtils
spring-web
- AbstractNameValueExpression
- AbstractWebEndpointMappingFactory
- AbstractWebRequestRule
- CompositeWebEndpointMappingRegistry
- CompositeWebRequestRule
- ConsumeMediaTypeExpression
- DelegatingHandlerMethodAdvice
- EnableWebExtension
- FilterRegistrationWebEndpointMappingFactory
- FilteringWebEndpointMappingRegistry
- GenericMediaTypeExpression
- HandlerMetadata
- HandlerMethodAdvice
- HandlerMethodArgumentInterceptor
- HandlerMethodArgumentsResolvedEvent
- HandlerMethodInterceptor
- HandlerMethodMetadata
- HttpUtils
- Jackson2WebEndpointMappingFactory
- MediaTypeExpression
- MediaTypeUtils
- NameValueExpression
- ProduceMediaTypeExpression
- PropertyConstants
- RegistrationWebEndpointMappingFactory
- RequestAttributesUtils
- RequestContextStrategy
- ServletRegistrationWebEndpointMappingFactory
- ServletWebEndpointMappingResolver
- SimpleWebEndpointMappingRegistry
- SmartWebEndpointMappingFactory
- SpringWebHelper
- SpringWebType
- UnknownSpringWebHelper
- WebEndpointMapping
- WebEndpointMappingFactory
- WebEndpointMappingFilter
- WebEndpointMappingRegistrar
- WebEndpointMappingRegistry
- WebEndpointMappingResolver
- WebEndpointMappingsReadyEvent
- WebEventPublisher
- WebExtensionBeanDefinitionRegistrar
- WebRequestConsumesRule
- WebRequestHeaderExpression
- WebRequestHeadersRule
- WebRequestMethodsRule
- WebRequestParamExpression
- WebRequestParamsRule
- WebRequestPattensRule
- WebRequestProducesRule
- WebRequestRule
- WebRequestUtils
- WebScope
- WebSource
- WebTarget
- WebType
- WebUtils
spring-webflux
- CompositeWebFilter
- ConsumingWebEndpointMappingAdapter
- DelegatingWebFilter
- EnableWebFluxExtension
- HandlerMappingWebEndpointMappingFactory
- HandlerMappingWebEndpointMappingResolver
- HandlerMetadataWebEndpointMappingFactory
- InterceptingHandlerMethodProcessor
- MonoUtils
- RequestContextWebFilter
- RequestHandledEventPublishingWebFilter
- RequestMappingMetadataWebEndpointMappingFactory
- RequestPredicateKind
- RequestPredicateVisitorAdapter
- ReversedProxyHandlerMapping
- RouterFunctionVisitorAdapter
- ServerRequestHandledEvent
- ServerWebRequest
- SpringWebFluxHelper
- StoringRequestBodyArgumentInterceptor
- StoringResponseBodyReturnValueInterceptor
- WebFluxExtensionBeanDefinitionRegistrar
- WebServerScope
- WebServerUtils
spring-webmvc
- AbstractPageRenderContextHandlerInterceptor
- AnnotatedMethodHandlerInterceptor
- ConfigurableContentNegotiationManagerWebMvcConfigurer
- ConsumingWebEndpointMappingAdapter
- ContentCachingFilter
- EnableWebMvcExtension
- EnableWebMvcExtensionListener
- ExclusiveViewResolverApplicationListener
- HandlerMappingWebEndpointMappingFactory
- HandlerMappingWebEndpointMappingResolver
- HandlerMetadataWebEndpointMappingFactory
- HandlerMethodArgumentResolverAdvice
- InterceptingHandlerMethodProcessor
- LazyCompositeHandlerInterceptor
- LoggingHandlerMethodArgumentResolverAdvice
- LoggingMethodHandlerInterceptor
- LoggingPageRenderContextHandlerInterceptor
- MethodHandlerInterceptor
- PropertyConstants
- RequestBodyAdviceAdapter
- RequestMappingMetadata
- RequestMappingMetadataWebEndpointMappingFactory
- RequestPredicateVisitorAdapter
- ResponseBodyAdviceAdapter
- ReversedProxyHandlerMapping
- RouterFunctionVisitorAdapter
- SpringWebMvcHelper
- StoringRequestBodyArgumentAdvice
- StoringResponseBodyReturnValueAdvice
- ViewResolverUtils
- ViewUtils
- WebMvcExtensionBeanDefinitionRegistrar
- WebMvcExtensionConfiguration
- WebMvcUtils
- WebUtils