Class AnnotatedPropertySourceLoader<A extends java.lang.annotation.Annotation>
- java.lang.Object
-
- io.microsphere.spring.context.annotation.BeanCapableImportCandidate
-
- io.microsphere.spring.config.context.annotation.AnnotatedPropertySourceLoader<A>
-
- Type Parameters:
A- The type of annotation that triggers property source loading
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanClassLoaderAware,org.springframework.beans.factory.BeanFactoryAware,org.springframework.context.annotation.ImportSelector,org.springframework.context.EnvironmentAware,org.springframework.context.ResourceLoaderAware
- Direct Known Subclasses:
PropertySourceExtensionLoader
public abstract class AnnotatedPropertySourceLoader<A extends java.lang.annotation.Annotation> extends BeanCapableImportCandidate implements org.springframework.context.annotation.ImportSelector
Abstract base class forImportSelectorimplementations that load aPropertySourcewhen aConfigurationclass is annotated with a specific annotation.This class provides a foundation for conditionally adding property sources to the Spring environment based on annotations present on configuration classes. Subclasses must implement the
loadPropertySource(AnnotationAttributes, AnnotationMetadata, String, MutablePropertySources)method to define how the property source is loaded.Example Usage
{@code public class MyPropertySourceLoader extends AnnotatedPropertySourceLoader{ - Since:
- 1.0.0
- Author:
- Mercy
- See Also:
ResourcePropertySourceLoader,PropertySourceExtensionLoader,ImportSelector
-
-
Field Summary
Fields Modifier and Type Field Description protected io.microsphere.logging.Loggerloggerprotected static java.lang.StringNAME_ATTRIBUTE_NAME-
Fields inherited from class io.microsphere.spring.context.annotation.BeanCapableImportCandidate
beanFactory, classLoader, environment, resourceLoader
-
-
Constructor Summary
Constructors Constructor Description AnnotatedPropertySourceLoader()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.lang.StringbuildDefaultPropertySourceName(org.springframework.core.annotation.AnnotationAttributes attributes, org.springframework.core.type.AnnotationMetadata metadata)Build the default name ofPropertySourceprotected java.lang.StringbuildPropertySourceName(org.springframework.core.annotation.AnnotationAttributes attributes, org.springframework.core.type.AnnotationMetadata metadata)Build the name ofPropertySourcejava.lang.Class<A>getAnnotationType()The annotation typeprotected java.lang.StringgetPropertySourceName()protected abstract voidloadPropertySource(org.springframework.core.annotation.AnnotationAttributes attributes, org.springframework.core.type.AnnotationMetadata metadata, java.lang.String propertySourceName, org.springframework.core.env.MutablePropertySources propertySources)Load thePropertySourceprotected java.lang.Class<A>resolveAnnotationType()protected java.lang.StringresolvePropertySourceName(org.springframework.core.annotation.AnnotationAttributes attributes, org.springframework.core.type.AnnotationMetadata metadata)Resolve the name ofPropertySourcejava.lang.String[]selectImports(org.springframework.core.type.AnnotationMetadata metadata)-
Methods inherited from class io.microsphere.spring.context.annotation.BeanCapableImportCandidate
getBeanFactory, getClassLoader, getEnvironment, getResourceLoader, setBeanClassLoader, setBeanFactory, setEnvironment, setResourceLoader
-
-
-
-
Field Detail
-
NAME_ATTRIBUTE_NAME
protected static final java.lang.String NAME_ATTRIBUTE_NAME
- See Also:
- Constant Field Values
-
logger
protected final io.microsphere.logging.Logger logger
-
-
Method Detail
-
resolveAnnotationType
protected java.lang.Class<A> resolveAnnotationType()
-
selectImports
public final java.lang.String[] selectImports(org.springframework.core.type.AnnotationMetadata metadata)
- Specified by:
selectImportsin interfaceorg.springframework.context.annotation.ImportSelector
-
resolvePropertySourceName
@Nonnull protected final java.lang.String resolvePropertySourceName(org.springframework.core.annotation.AnnotationAttributes attributes, org.springframework.core.type.AnnotationMetadata metadata)Resolve the name ofPropertySource- Parameters:
attributes-AnnotationAttributesmetadata-AnnotationMetadata- Returns:
- non-null
-
buildPropertySourceName
@Nullable protected java.lang.String buildPropertySourceName(org.springframework.core.annotation.AnnotationAttributes attributes, org.springframework.core.type.AnnotationMetadata metadata)Build the name ofPropertySource- Parameters:
attributes-AnnotationAttributesmetadata-AnnotationMetadata- Returns:
- the attribute value of annotation if the
"name"attribute present, ornull
-
buildDefaultPropertySourceName
@Nonnull protected java.lang.String buildDefaultPropertySourceName(org.springframework.core.annotation.AnnotationAttributes attributes, org.springframework.core.type.AnnotationMetadata metadata)Build the default name ofPropertySource- Parameters:
attributes-AnnotationAttributesmetadata-AnnotationMetadata- Returns:
- non-null
-
loadPropertySource
@Nullable protected abstract void loadPropertySource(org.springframework.core.annotation.AnnotationAttributes attributes, org.springframework.core.type.AnnotationMetadata metadata, java.lang.String propertySourceName, org.springframework.core.env.MutablePropertySources propertySources) throws java.lang.ThrowableLoad thePropertySource- Parameters:
attributes-AnnotationAttributesmetadata-AnnotationMetadatapropertySourceName- the name ofPropertySourcepropertySources-MutablePropertySourcesto be added- Throws:
java.lang.Throwable- the failure of the loading
-
getAnnotationType
@Nonnull public final java.lang.Class<A> getAnnotationType()
The annotation type- Returns:
- non-null
-
getPropertySourceName
protected java.lang.String getPropertySourceName()
-
-