首页 > 其他分享 >SpringBoot复习:(42)WebServerCustomizer的customize方法是在哪里被调用的?

SpringBoot复习:(42)WebServerCustomizer的customize方法是在哪里被调用的?

时间:2023-08-21 17:36:14浏览次数:47  
标签:容器 调用 SpringBoot BeanPostProcessor customize Spring 42 方法 WebServerFactoryCustom


ServletWebServletAutoConfiguration类定义如下:

SpringBoot复习:(42)WebServerCustomizer的customize方法是在哪里被调用的?_后端


可以看到其中通过@Import注解导入了其内部类BeanPostProcessorRegister。

SpringBoot复习:(42)WebServerCustomizer的customize方法是在哪里被调用的?_spring boot_02


BeanPostProcessor中定义的registerBeanDefinition方法会被Spring容器调用。

SpringBoot复习:(42)WebServerCustomizer的customize方法是在哪里被调用的?_后端_03


registerBeanDefinitions方法调用了RegistrySyntheticBeanIfMissing方法,这个方法代码如下:

SpringBoot复习:(42)WebServerCustomizer的customize方法是在哪里被调用的?_后端_04


可以看到它把传入的参数创建成BeanDefinition对象,然后注册到了Spring容器,而这个方法第三个参数为WebServerFactoryCustomizerBeanPostProcessor,所以就向Spring容器注册了WebServerFactoryCustomizerBeanPostProcessor类型的bean,

WebServerFactoryCustomizerBeanPostProcessor代码如下:

SpringBoot复习:(42)WebServerCustomizer的customize方法是在哪里被调用的?_内部类_05

SpringBoot复习:(42)WebServerCustomizer的customize方法是在哪里被调用的?_java_06


因为它是BeanPostProcessor,所以它的postProcessBeforeInitialization方法会被Spring容器调用,从图中可以看到,postProcessBeforeInitialization方法调用了容器中所有实现了WebServerFactoryCustomizer接口的bean的customize方法。


标签:容器,调用,SpringBoot,BeanPostProcessor,customize,Spring,42,方法,WebServerFactoryCustom
From: https://blog.51cto.com/amadeusliu/7177765

相关文章