Spring源码分析-bean的初始化过程
2021-05-02 01:29
标签:post with name rsa ring 注解 on() sso ESS Spring源码分析-bean的初始化过程 标签:post with name rsa ring 注解 on() sso ESS 原文地址:https://www.cnblogs.com/lighter-blog/p/13205669.html初始化过程
源码分析
/**
* 获取 BeanPostProcessor,执行 postProcessBeforeInitialization 方法
*/
if (mbd == null || !mbd.isSynthetic()) {
wrappedBean = applyBeanPostProcessorsBeforeInitialization(wrappedBean, beanName);
}
/**
* 执行 bean 指定的初始化方法:InitializingBean 接口的 afterPropertiesSet 方法,@Bean 注解指定的初始化方法
*/
try {
invokeInitMethods(beanName, wrappedBean, mbd);
}
catch (Throwable ex) {
throw new BeanCreationException(
(mbd != null ? mbd.getResourceDescription() : null),
beanName, "Invocation of init method failed", ex);
}
/**
* 获取 BeanPostProcessor,执行 postProcessAfterInitialization 方法
*/
if (mbd == null || !mbd.isSynthetic()) {
wrappedBean = applyBeanPostProcessorsAfterInitialization(wrappedBean, beanName);
}
protected void invokeInitMethods(String beanName, final Object bean, @Nullable RootBeanDefinition mbd)
throws Throwable {
boolean isInitializingBean = (bean instanceof InitializingBean);
if (isInitializingBean && (mbd == null || !mbd.isExternallyManagedInitMethod("afterPropertiesSet"))) {
if (logger.isTraceEnabled()) {
logger.trace("Invoking afterPropertiesSet() on bean with name ‘" + beanName + "‘");
}
if (System.getSecurityManager() != null) {
try {
AccessController.doPrivileged((PrivilegedExceptionAction