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.AutowireCandidateResolver
protected final io.microsphere.logging.Logger
protected ResolvableDependencyTypeFilter
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
resolve
(Constructor constructor, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> dependentBeanNames) Resolve the bean names as the dependencies from the specifiedconstructor
void
resolve
(Field field, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> dependentBeanNames) Resolve the bean names as the dependencies from the specifiedfield
void
resolve
(Method method, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> dependentBeanNames) Resolve the bean names as the dependencies from the specifiedmethod
void
resolve
(Parameter parameter, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> dependentBeanNames) Resolve the bean names as the dependencies from the specifiedparameter
protected String
resolveDependentBeanNameByName
(Field field, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) protected String
resolveDependentBeanNameByName
(Parameter parameter, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) protected String
resolveDependentBeanNameByName
(org.springframework.beans.factory.config.DependencyDescriptor dependencyDescriptor) protected void
resolveDependentBeanNamesByType
(Supplier<Type> typeSupplier, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> dependentBeanNames) protected Class<?>
resolveDependentType
(Type type) void
setBeanFactory
(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:InjectionPointDependencyResolver
Resolve the bean names as the dependencies from the specifiedfield
- Specified by:
resolve
in interfaceInjectionPointDependencyResolver
- Parameters:
field
- thefield
may be an injection pointbeanFactory
-ConfigurableListableBeanFactory
dependentBeanNames
- 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:InjectionPointDependencyResolver
Resolve the bean names as the dependencies from the specifiedmethod
- Specified by:
resolve
in interfaceInjectionPointDependencyResolver
- Parameters:
method
- themethod
may be an injection pointbeanFactory
-ConfigurableListableBeanFactory
dependentBeanNames
- 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:InjectionPointDependencyResolver
Resolve the bean names as the dependencies from the specifiedconstructor
- Specified by:
resolve
in interfaceInjectionPointDependencyResolver
- Parameters:
constructor
- theconstructor
may be an injection pointbeanFactory
-ConfigurableListableBeanFactory
dependentBeanNames
- 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:InjectionPointDependencyResolver
Resolve the bean names as the dependencies from the specifiedparameter
- Specified by:
resolve
in interfaceInjectionPointDependencyResolver
- Parameters:
parameter
- the specifiedparameter
of a method or constructor was annotated by the annotationbeanFactory
-ConfigurableListableBeanFactory
dependentBeanNames
- the dependent bean names to be manipulated
-
setBeanFactory
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException - Specified by:
setBeanFactory
in 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
-