Source code analysis of spring learning -- ConfigurableBeanFactory

ConfigurableBeanFactory

ConfigurableBeanFactory inherits HierarchicalBeanFactory, SingletonBeanRegistry Two interfaces. This interface will be implemented by most bean factories.

Class structure

This method, more than before, is not complete.

constant

String SCOPE_SINGLETON = "singleton";//Single case
String SCOPE_PROTOTYPE = "prototype";//Multiple cases

Method analysis

Set parent container

void setParentBeanFactory(BeanFactory parentBeanFactory) throws IllegalStateException;

Class loader

// Set class loader
void setBeanClassLoader(@Nullable ClassLoader beanClassLoader);
// Get class loader
ClassLoader getBeanClassLoader();
// Set the temporary loader. If load time weaving is involved, only one temporary class loader is usually specified to ensure that the actual bean class is loaded as late as possible
void setTempClassLoader(@Nullable ClassLoader tempClassLoader);
// Get temporary loader
ClassLoader getTempClassLoader();

The metadata cache of the bean, which is true by default. If it is false, every time you create a bean, you need to get information from the classloader.

// Set whether to cache
void setCacheBeanMetadata(boolean cacheBeanMetadata);
// Get whether to cache
boolean isCacheBeanMetadata();

Expression resolver of bean

// Set up expression resolver
void setBeanExpressionResolver(@Nullable BeanExpressionResolver resolver);
// Get expression resolver
BeanExpressionResolver getBeanExpressionResolver();

Type converter

// Set type converter
void setConversionService(@Nullable ConversionService conversionService);
// Get type converter
ConversionService getConversionService();

Attribute editor

// Add Attribute Editor
void addPropertyEditorRegistrar(PropertyEditorRegistrar registrar);
// Register the Attribute Editor for the given type
void registerCustomEditor(Class<?> requiredType, Class<? extends PropertyEditor> propertyEditorClass);
// Initialize the given PropertyEditorRegistry with a custom editor registered in this BeanFactory
void copyRegisteredEditorsTo(PropertyEditorRegistry registry);

Type converter

// Set type converter
void setTypeConverter(TypeConverter typeConverter);
// Get type converter
TypeConverter getTypeConverter();

Add a string parser for embedded values, such as comment properties

// Add to
void addEmbeddedValueResolver(StringValueResolver valueResolver);
// Whether there is
boolean hasEmbeddedValueResolver();
// Resolve the given embedded value
String resolveEmbeddedValue(String value);

Post processor

// Add post processor
void addBeanPostProcessor(BeanPostProcessor beanPostProcessor);
// Get the number of post processors
int getBeanPostProcessorCount();

Scope of action

// Registration scope
void registerScope(String scopeName, Scope scope);
// Get scope, except for single and multiple cases
String[] getRegisteredScopeNames();
// Get scope by name
Scope getRegisteredScope(String scopeName);

Security scope

// Get security scope
AccessControlContext getAccessControlContext();

Configure replication. Replication includes all standard configuration settings as well as bean post processor, scope, and factory specific internal settings. You should not include any metadata for the actual bean definition, such as the BeanDefinition object and the bean name alias.

void copyConfigurationFrom(ConfigurableBeanFactory otherFactory);

alias

// Registration alias
void registerAlias(String beanName, String alias) throws BeanDefinitionStoreException;
// Remove alias according to valueResolver
void resolveAliases(StringValueResolver valueResolver);

BeanDefinition

// Merge bean definitions, including those inherited from the parent class
BeanDefinition getMergedBeanDefinition(String beanName) throws NoSuchBeanDefinitionException;

FactoryBean

// FactoryBean or not
boolean isFactoryBean(String name) throws NoSuchBeanDefinitionException;

bean being created

// To set whether a bean is being created or not, it is necessary to solve the problem of circular dependency
void setCurrentlyInCreation(String beanName, boolean inCreation);
boolean isCurrentlyInCreation(String beanName);

Dependent bean s

// Register a dependency bean of a specified bean
void registerDependentBean(String beanName, String dependentBeanName);
// Get all beans that depend on the specified bean
String[] getDependentBeans(String beanName);
// Get all dependencies of the specified bean
String[] getDependenciesForBean(String beanName);

Destroy bean

// Destroy the specified bean
void destroyBean(String beanName, Object beanInstance);
// Destroy the bean of the specified scope
void destroyScopedBean(String beanName);
// Destroy all singleton bean s
void destroySingletons();

Tags: Java Attribute

Posted on Mon, 04 Nov 2019 09:50:16 -0800 by ryanschefke