Class AbstractInjectionPointDependencyResolver
java.lang.Object
io.microsphere.spring.beans.factory.AbstractInjectionPointDependencyResolver
- All Implemented Interfaces:
InjectionPointDependencyResolver,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanFactoryAware
- Direct Known Subclasses:
AnnotatedInjectionPointDependencyResolver,BeanMethodInjectionPointDependencyResolver,ConstructionInjectionPointDependencyResolver
public abstract class AbstractInjectionPointDependencyResolver
extends Object
implements InjectionPointDependencyResolver, org.springframework.beans.factory.BeanFactoryAware
Abstract base class for implementing
InjectionPointDependencyResolver.
This class provides a foundation for resolving dependencies at injection points within Spring-managed beans.
It handles common tasks such as bean factory awareness, dependency type resolution, and logging using the
Logger interface.
Key Responsibilities
- Tracking and resolving dependencies based on injection points (fields, methods, constructors).
- Filtering resolvable dependency types via the configured
ResolvableDependencyTypeFilter. - Providing consistent logging capabilities through the injected logger.
- Supporting custom resolution logic by allowing subclasses to implement specific strategies.
Example Usage
Basic Implementation
public class MyDependencyResolver extends AbstractInjectionPointDependencyResolver {
// Custom implementation details here
}
Resolving Dependencies from a Field
public void resolve(Field field, ConfigurableListableBeanFactory beanFactory, Set<String> dependentBeanNames) {
String dependentBeanName = resolveDependentBeanNameByName(field, beanFactory);
if (dependentBeanName == null) {
resolveDependentBeanNamesByType(field::getGenericType, beanFactory, dependentBeanNames);
} else {
dependentBeanNames.add(dependentBeanName);
}
}
Resolving Dependencies from a Method Parameter
public void resolve(Parameter parameter, ConfigurableListableBeanFactory beanFactory, Set<String> dependentBeanNames) {
String dependentBeanName = resolveDependentBeanNameByName(parameter, beanFactory);
if (dependentBeanName == null) {
resolveDependentBeanNamesByType(parameter::getParameterizedType, beanFactory, dependentBeanNames);
} else {
dependentBeanNames.add(dependentBeanName);
}
}
- Since:
- 1.0.0
- Author:
- Mercy
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.springframework.beans.factory.support.AutowireCandidateResolverprotected final io.microsphere.logging.Loggerprotected ResolvableDependencyTypeFilter -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidresolve(Constructor constructor, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> dependentBeanNames) Resolve the bean names as the dependencies from the specifiedconstructorvoidresolve(Field field, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> dependentBeanNames) Resolve the bean names as the dependencies from the specifiedfieldvoidresolve(Method method, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> dependentBeanNames) Resolve the bean names as the dependencies from the specifiedmethodvoidresolve(Parameter parameter, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> dependentBeanNames) Resolve the bean names as the dependencies from the specifiedparameterprotected StringresolveDependentBeanNameByName(Field field, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) protected StringresolveDependentBeanNameByName(Parameter parameter, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) protected StringresolveDependentBeanNameByName(org.springframework.beans.factory.config.DependencyDescriptor dependencyDescriptor) protected voidresolveDependentBeanNamesByType(Supplier<Type> typeSupplier, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> dependentBeanNames) protected Class<?>resolveDependentType(Type type) voidsetBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
-
Field Details
-
logger
protected final io.microsphere.logging.Logger logger -
resolvableDependencyTypeFilter
-
autowireCandidateResolver
@Nonnull protected org.springframework.beans.factory.support.AutowireCandidateResolver autowireCandidateResolver
-
-
Constructor Details
-
AbstractInjectionPointDependencyResolver
public AbstractInjectionPointDependencyResolver()
-
-
Method Details
-
resolve
public void resolve(Field field, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> dependentBeanNames) Description copied from interface:InjectionPointDependencyResolverResolve the bean names as the dependencies from the specifiedfield- Specified by:
resolvein interfaceInjectionPointDependencyResolver- Parameters:
field- thefieldmay be an injection pointbeanFactory-ConfigurableListableBeanFactorydependentBeanNames- the dependent bean names to be manipulated
-
resolve
public void resolve(Method method, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> dependentBeanNames) Description copied from interface:InjectionPointDependencyResolverResolve the bean names as the dependencies from the specifiedmethod- Specified by:
resolvein interfaceInjectionPointDependencyResolver- Parameters:
method- themethodmay be an injection pointbeanFactory-ConfigurableListableBeanFactorydependentBeanNames- the dependent bean names to be manipulated
-
resolve
public void resolve(Constructor constructor, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> dependentBeanNames) Description copied from interface:InjectionPointDependencyResolverResolve the bean names as the dependencies from the specifiedconstructor- Specified by:
resolvein interfaceInjectionPointDependencyResolver- Parameters:
constructor- theconstructormay be an injection pointbeanFactory-ConfigurableListableBeanFactorydependentBeanNames- the dependent bean names to be manipulated
-
resolve
public void resolve(Parameter parameter, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> dependentBeanNames) Description copied from interface:InjectionPointDependencyResolverResolve the bean names as the dependencies from the specifiedparameter- Specified by:
resolvein interfaceInjectionPointDependencyResolver- Parameters:
parameter- the specifiedparameterof a method or constructor was annotated by the annotationbeanFactory-ConfigurableListableBeanFactorydependentBeanNames- the dependent bean names to be manipulated
-
setBeanFactory
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException - Specified by:
setBeanFactoryin interfaceorg.springframework.beans.factory.BeanFactoryAware- Throws:
org.springframework.beans.BeansException
-
resolveDependentBeanNameByName
-
resolveDependentBeanNameByName
-
resolveDependentBeanNameByName
protected String resolveDependentBeanNameByName(org.springframework.beans.factory.config.DependencyDescriptor dependencyDescriptor) -
resolveDependentBeanNamesByType
-
resolveDependentType
-