Class ResourcePropertySourceLoader
java.lang.Object
io.microsphere.spring.context.annotation.BeanCapableImportCandidate
io.microsphere.spring.context.annotation.AnnotatedBeanCapableImportCandidate<A>
io.microsphere.spring.context.annotation.AnnotatedBeanCapableImportSelector<A>
io.microsphere.spring.config.context.annotation.AnnotatedPropertySourceLoader<A>
io.microsphere.spring.config.context.annotation.PropertySourceExtensionLoader<ResourcePropertySource,PropertySourceExtensionAttributes<ResourcePropertySource>>
io.microsphere.spring.config.context.annotation.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
The
PropertySourceExtensionLoader Class for ResourcePropertySource- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class io.microsphere.spring.config.context.annotation.PropertySourceExtensionLoader
PropertySourceExtensionLoader.PropertySourceResource, PropertySourceExtensionLoader.ResourcePropertySourcesRefresher -
Field Summary
Fields inherited from class io.microsphere.spring.config.context.annotation.AnnotatedPropertySourceLoader
NAME_ATTRIBUTE_NAMEFields inherited from class io.microsphere.spring.context.annotation.AnnotatedBeanCapableImportCandidate
annotationTypeFields inherited from class io.microsphere.spring.context.annotation.BeanCapableImportCandidate
applicationContext, beanFactory, classLoader, environment, logger, NO_CLASS_TO_IMPORT, registry, resourceLoader -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidInitializes theResourcePatternResolverandPathMatcherused for resolving resource patterns after all bean properties have been set.protected voidconfigureResourcePropertySourcesRefresher(PropertySourceExtensionAttributes<ResourcePropertySource> extensionAttributes, List<PropertySourceExtensionLoader.PropertySourceResource> propertySourceResources, org.springframework.core.env.CompositePropertySource propertySource, PropertySourceExtensionLoader.ResourcePropertySourcesRefresher refresher) Configures thePropertySourceExtensionLoader.ResourcePropertySourcesRefresherby setting up aStandardFileWatchServicethat watches file-based resources for changes.voiddestroy()Stops the internalStandardFileWatchServiceif it was started, releasing file watching resources.booleanisResourcePattern(String resourceValue) Determines whether the given resource value is a pattern containing wildcards (e.g.protected org.springframework.core.io.Resource[]resolveResources(PropertySourceExtensionAttributes<ResourcePropertySource> extensionAttributes, String propertySourceName, String resourceValue) Resolves theResourceinstances matching the given resource value pattern using the internalResourcePatternResolver.Methods inherited from class io.microsphere.spring.config.context.annotation.PropertySourceExtensionLoader
addPropertySource, buildExtensionAttributes, createInstance, createPropertySourceFactory, createResourceComparator, createResourcePropertySource, createResourcePropertySourceName, getExtensionAttributesType, loadPropertySource, loadPropertySource, resolveExtensionAttributesType, resolvePropertySourceResourcesMethods inherited from class io.microsphere.spring.config.context.annotation.AnnotatedPropertySourceLoader
buildDefaultPropertySourceName, buildPropertySourceName, getAnnotationType, getPropertySourceName, resolvePropertySourceName, selectImportsMethods inherited from class io.microsphere.spring.context.annotation.AnnotatedBeanCapableImportSelector
selectImportsMethods inherited from class io.microsphere.spring.context.annotation.AnnotatedBeanCapableImportCandidate
getAnnotationAttributes, getEnabledPropertyName, getGlobalEnabledPropertyName, isEnabled, resolveAnnotationType, resolveGenericMethods inherited from class io.microsphere.spring.context.annotation.BeanCapableImportCandidate
getAnnotationAttributes, getApplicationContext, getBeanDefinitionRegistry, getBeanFactory, getClassLoader, getEnvironment, getOverriddenAnnotationAttributes, getResourceLoader, setApplicationContext, setBeanClassLoader, setBeanFactory, setEnvironment, setResourceLoaderMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.annotation.ImportSelector
getExclusionFilter
-
Constructor Details
-
ResourcePropertySourceLoader
public ResourcePropertySourceLoader()
-
-
Method Details
-
afterPropertiesSet
Initializes theResourcePatternResolverandPathMatcherused 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:
afterPropertiesSetin interfaceorg.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 theResourceinstances matching the given resource value pattern using the internalResourcePatternResolver.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:
resolveResourcesin classPropertySourceExtensionLoader<ResourcePropertySource,PropertySourceExtensionAttributes<ResourcePropertySource>> - Parameters:
extensionAttributes- the extension attributes of theResourcePropertySourceannotationpropertySourceName- the name of the property source being loadedresourceValue- the resource location pattern to resolve (e.g."classpath*:/META-INF/test/*.properties")- Returns:
- an array of resolved
Resourceinstances matching the pattern - Throws:
Throwable- if resource resolution fails
-
isResourcePattern
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:
isResourcePatternin classPropertySourceExtensionLoader<ResourcePropertySource,PropertySourceExtensionAttributes<ResourcePropertySource>> - Parameters:
resourceValue- the resource location string to test- Returns:
trueif the resource value contains wildcard patterns,falseotherwise
-
configureResourcePropertySourcesRefresher
protected void configureResourcePropertySourcesRefresher(PropertySourceExtensionAttributes<ResourcePropertySource> extensionAttributes, List<PropertySourceExtensionLoader.PropertySourceResource> propertySourceResources, org.springframework.core.env.CompositePropertySource propertySource, PropertySourceExtensionLoader.ResourcePropertySourcesRefresher refresher) throws Throwable Configures thePropertySourceExtensionLoader.ResourcePropertySourcesRefresherby setting up aStandardFileWatchServicethat 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:
configureResourcePropertySourcesRefresherin classPropertySourceExtensionLoader<ResourcePropertySource,PropertySourceExtensionAttributes<ResourcePropertySource>> - Parameters:
extensionAttributes- the extension attributes of theResourcePropertySourceannotationpropertySourceResources- the list of property source resources to watchpropertySource- the composite property source that aggregates the individual sourcesrefresher- the refresher to invoke when file changes are detected- Throws:
Throwable- if configuring the file watch service fails
-
destroy
Stops the internalStandardFileWatchServiceif 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:
destroyin interfaceorg.springframework.beans.factory.DisposableBean- Throws:
Exception- if stopping the file watch service fails
-