Several of the more important spring extension points

BeanFactoryPostProcessor

Implement the interface can before the spring of bean to create, modify define the properties of the bean. That is, Spring BeanFactoryPostProcessor allowed to read the configuration metadata container before instantiating any other bean, and may be modified as needed, for example, from the scope of the bean singleton to the prototype, the value of the property may be modified to swap. You can configure multiple BeanFactoryPostProcessor, and controls the order of execution by setting the respective BeanFactoryPostProcessor 'order' attribute.

Note: BeanFactoryPostProcessor is spring loaded container after the bean definition file, executed before the bean is instantiated.

void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory);

 

————————————————

Original link: https://blog.csdn.net/caihaijiang/java/article/details/35552859

 

Spring is in the internal realization of this @Configuration configuration class CGLIB agent (ConfigurationClassPostProcessor # postProcessBeanFactory)

BeanDefinitionRegistryPostProcessor

This interface inherits BeanFactoryPostProcessor interface. Information to be loaded in all the bean definitions, implementation of our expansion when the bean instance has not been created; look at it from a spring source BeanFactoryPostProcessor priority to the implementation of (first traverse the BeanDefinitionRegistryPostProcessor); BeanDefinitionRegistryPostProcessor to use container and then add some extra components.

 

Spring is also based on internal bean scanning it implements registration.

 

BeanFactoryPostProcessor can modify individual Bean definitions ( the BeanDefinition ), BeanDefinitionRegistryPostProcessor dynamically register Bean.

 

The following two methods:

void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory);


void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) ;
BeanPostProcessor

The BeanPostProcessor, after the spring can be instantiated bean container, before and after performing the initialization method of the bean, add their own processing logic. Here that the initialization method, refer to the following two:

1) bean InitializingBean implements the interface, the corresponding method is afterPropertiesSet

2) When bean defined, by methods set init-method

 

Note: BeanPostProcessor container is spring loaded bean definitions and examples of the bean after execution. BeanPostProcessor execution order that after BeanFactoryPostProcessor.

————————————————

Original link: https://blog.csdn.net/caihaijiang/java/article/details/35552859

 

ImportSelector

ImportSelector class can be loaded by way of @Import usually start classes or class configuration.

ImportSelector selectImports interface provides a method that returns an array, i.e. the name of the class instance. spring bean definition will create these class names, because of this process is an internal spring to help us to do, we can not create interference to register the bean definition.

Specific applications can be found in: https://www.cnblogs.com/tianboblog/p/12619262.html

String[] selectImports(AnnotationMetadata importingClassMetadata);
ImportBeanDefinitionRegistrar

ImportBeanDefinitionRegistrar class can only be loaded by other classes @Import way, usually starting classes or configuration class.

The more typical application is mybatis.spring in realized @ MapperScan comment.

See: https://www.cnblogs.com/tianboblog/p/12618057.html

void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {}

It is relative to ImportSelector more powerful, providing a registry, bean can register directly through it.

Guess you like

Origin www.cnblogs.com/tianboblog/p/12625829.html