Spring - BeanPostProcessors 扩展接口

news2025/1/21 22:00:16

文章目录

  • Pre
  • Bean的生成过程
  • org.springframework.beans.factory.config.BeanPostProcessor 介绍
  • ApplicationContext注册Bean PostProcessor源码解析
    • AbstractApplicationContext#refresh
    • AbstractApplicationContext#registerBeanPostProcessors
    • PostProcessorRegistrationDelegate.registerBeanPostProcessors
  • 回调BeanPostProcessors的时机源码解析
  • 扩展示例
  • 小结

在这里插入图片描述


Pre

Spring Boot - 扩展接口一览

在这里插入图片描述


Bean的生成过程

在这里插入图片描述


org.springframework.beans.factory.config.BeanPostProcessor 介绍

public interface BeanPostProcessor {


	@Nullable
	default Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		return bean;
	}

	@Nullable
	default Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		return bean;
	}

}


在这里插入图片描述

如果BeanPostProcessors接囗的实现类被注册到ioc容器,那么该容器的每个Bean在调用初始化方法之前,都会获得该接口实现类的一个回调。

要使用BeanPostProcessord回调,就必须先在容器中注册实现该接口的类,那么如何注册呢?

  • 若使用BeanFactory,则必须要显示的调用其addBeanPostProcessor方法进行注册,参数为BeanPostProcessor现类的实例;

  • 使用ApplicationContext,那么容器会在配置文件在中自动寻找实现了 BeanPostProcessor口的Bean,然后自动注册,我们只需要配置个BeanPostProcessor现类的Bean可以了。

  • 多个的BeanPostProcessorg实现类,只要实现Ordered接口,设置order属性就可以很轻确定不同实现类的处理顺序了;

  • 接口中的两个方法都要将传入的bean回,不能返回null,如果返回的是nu么我们通过getBean将得不到目标


ApplicationContext注册Bean PostProcessor源码解析

AbstractApplicationContext#refresh

org.springframework.context.support.AbstractApplicationContext#refresh

来看下关键代码

public void refresh() throws BeansException, IllegalStateException {
	 
	........

	// Register bean processors that intercept bean creation.
	registerBeanPostProcessors(beanFactory);
 
	........
	// Instantiate all remaining (non-lazy-init) singletons.
	// 实例化剩余的所有非延迟加载单例对象
	// 在上面的registerBeanPostProcessors中已经把所有BeanPostProcessors所有对象都已经实例化过了

	//  这加载的时候会判断bean是不是 FactoryBean类型的
	//  如果是FactoryBean类型,则getBean(&beanName),这里是把FactoryBean本身的对象给实例化了,而没有调它的getObject方法;
	// 还要判断是不是SmartFactoryBean类型的,SmartFactoryBean继承了FactoryBean接口;但是它多了一个	boolean isEagerInit();方法;这个方法就是判断是否需要通过FactoryBean的getObject()生成实例;
	// 如果不是FactoryBean类型,直接getBean就行了;
	
	// 还要判断是不是SmartInitializingSingleton接口,这个接口有个afterSingletonsInstantiated方法;
	// 循环所以bean判断是不是这个类型的,只要是这个类型就调用afterSingletonsInstantiated方法;
	finishBeanFactoryInitialization(beanFactory);

	........	 
			
	}

AbstractApplicationContext#registerBeanPostProcessors

先看 registerBeanPostProcessors

	/**
	 * Instantiate and register all BeanPostProcessor beans,
	 * respecting explicit order if given.
	 * <p>Must be called before any instantiation of application beans.
	 */
	protected void registerBeanPostProcessors(ConfigurableListableBeanFactory beanFactory) {
		PostProcessorRegistrationDelegate.registerBeanPostProcessors(beanFactory, this);
	}

PostProcessorRegistrationDelegate.registerBeanPostProcessors

public static void registerBeanPostProcessors(
			ConfigurableListableBeanFactory beanFactory, AbstractApplicationContext applicationContext) {
		/**
		* 代码走到了这里的时候其实 BeanDefinition数据已经被加载了,只是bean还没有被实例化
		所以这个是去容器里面找到所有类型为BeanPostProcessor的beanName
		*/
		String[] postProcessorNames = beanFactory.getBeanNamesForType(BeanPostProcessor.class, true, false);

	
		int beanProcessorTargetCount = beanFactory.getBeanPostProcessorCount() + 1 + postProcessorNames.length;
		
		beanFactory.addBeanPostProcessor(new BeanPostProcessorChecker(beanFactory, beanProcessorTargetCount));

		// 优先级最高的BeanPostProcessors,这类最先调用;需要实现PriorityOrdered接口
		List<BeanPostProcessor> priorityOrderedPostProcessors = new ArrayList<BeanPostProcessor>();
		//内部BeanPostProcessors
		List<BeanPostProcessor> internalPostProcessors = new ArrayList<BeanPostProcessor>();
		//继承了Ordered接口,优先级比上面低一点
		List<String> orderedPostProcessorNames = new ArrayList<String>();
		//这就是普通的了,优先级最低
		List<String> nonOrderedPostProcessorNames = new ArrayList<String>();
		
		//下面的这些代码就是遍历所有postProcessorNames,按优先级排序;类型PriorityOrdered>Ordered>普通;在这个类型基础上,还要对他们的order属性就行排序;
		for (String ppName : postProcessorNames) {
			if (beanFactory.isTypeMatch(ppName, PriorityOrdered.class)) {
				BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
				priorityOrderedPostProcessors.add(pp);
				if (pp instanceof MergedBeanDefinitionPostProcessor) {
					internalPostProcessors.add(pp);
				}
			}
			else if (beanFactory.isTypeMatch(ppName, Ordered.class)) {
				orderedPostProcessorNames.add(ppName);
			}
			else {
				nonOrderedPostProcessorNames.add(ppName);
			}
		}

		// First, register the BeanPostProcessors that implement PriorityOrdered.
		sortPostProcessors(beanFactory, priorityOrderedPostProcessors);
		registerBeanPostProcessors(beanFactory, priorityOrderedPostProcessors);

		// Next, register the BeanPostProcessors that implement Ordered.
		List<BeanPostProcessor> orderedPostProcessors = new ArrayList<BeanPostProcessor>();
		for (String ppName : orderedPostProcessorNames) {
			BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
			orderedPostProcessors.add(pp);
			if (pp instanceof MergedBeanDefinitionPostProcessor) {
				internalPostProcessors.add(pp);
			}
		}
		sortPostProcessors(beanFactory, orderedPostProcessors);
		registerBeanPostProcessors(beanFactory, orderedPostProcessors);

		// Now, register all regular BeanPostProcessors.
		List<BeanPostProcessor> nonOrderedPostProcessors = new ArrayList<BeanPostProcessor>();
		for (String ppName : nonOrderedPostProcessorNames) {
		//这里要注意一下了,看到没有,这个时候已经调用了getBean来生成实例对象了;
			BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
			nonOrderedPostProcessors.add(pp);
			if (pp instanceof MergedBeanDefinitionPostProcessor) {
				internalPostProcessors.add(pp);
			}
		}
		registerBeanPostProcessors(beanFactory, nonOrderedPostProcessors);

		// 排序
		sortPostProcessors(beanFactory, internalPostProcessors);
		//注册
		registerBeanPostProcessors(beanFactory, internalPostProcessors);

		// 加入ApplicationListenerDetector
		beanFactory.addBeanPostProcessor(new ApplicationListenerDetector(applicationContext));
	}

	/**
	 * 注册 BeanPostProcessor beans.
	 * 容器中beanPostProcessors是一个ArrayList来持有这些BeanPostProcessors
	 */
	private static void registerBeanPostProcessors(
			ConfigurableListableBeanFactory beanFactory, List<BeanPostProcessor> postProcessors) {

		for (BeanPostProcessor postProcessor : postProcessors) {
			beanFactory.addBeanPostProcessor(postProcessor);
		}
	}
@Override
	public void addBeanPostProcessor(BeanPostProcessor beanPostProcessor) {
		Assert.notNull(beanPostProcessor, "BeanPostProcessor must not be null");
		this.beanPostProcessors.remove(beanPostProcessor);
		this.beanPostProcessors.add(beanPostProcessor);
		//将是否 hasInstantiationAwareBeanPostProcessors设置为true 
		if (beanPostProcessor instanceof InstantiationAwareBeanPostProcessor) {
			this.hasInstantiationAwareBeanPostProcessors = true;
		}
		if (beanPostProcessor instanceof DestructionAwareBeanPostProcessor) {
			this.hasDestructionAwareBeanPostProcessors = true;
		}
	}


回调BeanPostProcessors的时机源码解析

org.springframework.context.support.PostProcessorRegistrationDelegate#registerBeanPostProcessors()
	BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
		org.springframework.beans.factory.support.AbstractBeanFactory#getBean
		  org.springframework.beans.factory.support.AbstractBeanFactory#doGetBean			

doGetBean 重点看

// Create bean instance.
if (mbd.isSingleton()) {
	sharedInstance = getSingleton(beanName, () -> {
		try {
			return createBean(beanName, mbd, args);
		}
		catch (BeansException ex) {
			// Explicitly remove instance from singleton cache: It might have been put there
			// eagerly by the creation process, to allow for circular reference resolution.
			// Also remove any beans that received a temporary reference to the bean.
			destroySingleton(beanName);
			throw ex;
		}
	});
	beanInstance = getObjectForBeanInstance(sharedInstance, name, beanName, mbd);
}

继续看 createBean

 org.springframework.context.support.PostProcessorRegistrationDelegate#registerBeanPostProcessors()
	BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
		org.springframework.beans.factory.support.AbstractBeanFactory#getBean
		  org.springframework.beans.factory.support.AbstractBeanFactory#doGetBean	
			  org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#createBean
					org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#doCreateBean

doCreateBean重点看

// Initialize the bean instance.
Object exposedObject = bean;
try {
    // 属性设置
	populateBean(beanName, mbd, instanceWrapper);
	// BeanPostProcessors两个方法都在这里面
	exposedObject = initializeBean(beanName, exposedObject, mbd);
}
org.springframework.context.support.PostProcessorRegistrationDelegate#registerBeanPostProcessors()
	BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
		org.springframework.beans.factory.support.AbstractBeanFactory#getBean
		  org.springframework.beans.factory.support.AbstractBeanFactory#doGetBean	
			  org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#createBean
					org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#doCreateBean
						org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#initializeBean

继续核心 initializeBean

protected Object initializeBean(String beanName, Object bean, @Nullable RootBeanDefinition mbd) {
		if (System.getSecurityManager() != null) {
			AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
				invokeAwareMethods(beanName, bean);
				return null;
			}, getAccessControlContext());
		}
		else {
		   // 检查Aware相关接口并设置相关依赖
			invokeAwareMethods(beanName, bean);
		}

		Object wrappedBean = bean;
		if (mbd == null || !mbd.isSynthetic()) {
		   // BeanPostProcessor前置处理
			wrappedBean = applyBeanPostProcessorsBeforeInitialization(wrappedBean, beanName);
		}

		try {
		   // 检查是否是InitializingBean以决定是否调用afterPropertiesSet方法 
		   // 检查是否配置有自定义的init-method方法
			invokeInitMethods(beanName, wrappedBean, mbd);
		}
		catch (Throwable ex) {
			throw new BeanCreationException(
					(mbd != null ? mbd.getResourceDescription() : null),
					beanName, "Invocation of init method failed", ex);
		}
		if (mbd == null || !mbd.isSynthetic()) {
		   // BeanPostProcessor后置处理
			wrappedBean = applyBeanPostProcessorsAfterInitialization(wrappedBean, beanName);
		}

		return wrappedBean;
	}

看下 applyBeanPostProcessorsAfterInitialization

   //注意 每一个实例对象触发这个的时候 都是执行所有的BeanPostProcessors实例对象

	@Override
	public Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName)
			throws BeansException {

		Object result = existingBean;
		for (BeanPostProcessor processor : getBeanPostProcessors()) {
			Object current = processor.postProcessAfterInitialization(result, beanName);
			//这里是循环
			//	result =BeanPostProcessor调用执行方法;返回的对象还是result,只是有可能被某个BeanPostProcessor加强了 beanProcessor.postProcessAfterInitialization(result, beanName);
			if (current == null) {
				return result;
			}
			result = current;
		}
		return result;
	}

扩展示例

package com.artisan.bootspringextend.testextends;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Configuration;

/**
 * @author 小工匠
 * @version 1.0
 * @description: TODO
 * @date 2022/11/27 21:22
 * @mark: show me the code , change the world
 */

@Slf4j
@Configuration
public class ExtendBeanPostProcessor  implements BeanPostProcessor {

 @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        log.info("beanName: {}-----> postProcessBeforeInitialization",beanName);
        return BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        log.info( "beanName: {} ------> postProcessAfterInitialization",beanName);
        return BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName);
    }
    
}
    

看日志

2022-11-27 22:07:40.269  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: bootSpringExtendApplication-----> postProcessBeforeInitialization
2022-11-27 22:07:40.271  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: bootSpringExtendApplication ------> postProcessAfterInitialization
2022-11-27 22:07:40.271  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.AutoConfigurationPackages-----> postProcessBeforeInitialization
2022-11-27 22:07:40.272  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.AutoConfigurationPackages ------> postProcessAfterInitialization
2022-11-27 22:07:40.273  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration-----> postProcessBeforeInitialization
2022-11-27 22:07:40.273  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration ------> postProcessAfterInitialization
2022-11-27 22:07:40.281  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration-----> postProcessBeforeInitialization
2022-11-27 22:07:40.281  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration ------> postProcessAfterInitialization
2022-11-27 22:07:40.284  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: objectNamingStrategy-----> postProcessBeforeInitialization
2022-11-27 22:07:40.284  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: objectNamingStrategy ------> postProcessAfterInitialization
2022-11-27 22:07:40.294  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: mbeanServer-----> postProcessBeforeInitialization
2022-11-27 22:07:40.294  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: mbeanServer ------> postProcessAfterInitialization
2022-11-27 22:07:40.297  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: mbeanExporter-----> postProcessBeforeInitialization
2022-11-27 22:07:40.297  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: mbeanExporter ------> postProcessAfterInitialization
2022-11-27 22:07:40.299  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration-----> postProcessBeforeInitialization
2022-11-27 22:07:40.299  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration ------> postProcessAfterInitialization
2022-11-27 22:07:40.303  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: springApplicationAdminRegistrar-----> postProcessBeforeInitialization
2022-11-27 22:07:40.304  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: springApplicationAdminRegistrar ------> postProcessAfterInitialization
2022-11-27 22:07:40.307  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.aop.AopAutoConfiguration$ClassProxyingConfiguration-----> postProcessBeforeInitialization
2022-11-27 22:07:40.307  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.aop.AopAutoConfiguration$ClassProxyingConfiguration ------> postProcessAfterInitialization
2022-11-27 22:07:40.308  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.aop.AopAutoConfiguration-----> postProcessBeforeInitialization
2022-11-27 22:07:40.308  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.aop.AopAutoConfiguration ------> postProcessAfterInitialization
2022-11-27 22:07:40.308  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration-----> postProcessBeforeInitialization
2022-11-27 22:07:40.308  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration ------> postProcessAfterInitialization
2022-11-27 22:07:40.310  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: applicationAvailability-----> postProcessBeforeInitialization
2022-11-27 22:07:40.310  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: applicationAvailability ------> postProcessAfterInitialization
2022-11-27 22:07:40.311  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration-----> postProcessBeforeInitialization
2022-11-27 22:07:40.311  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration ------> postProcessAfterInitialization
2022-11-27 22:07:40.311  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.context.properties.BoundConfigurationProperties-----> postProcessBeforeInitialization
2022-11-27 22:07:40.311  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.context.properties.BoundConfigurationProperties ------> postProcessAfterInitialization
2022-11-27 22:07:40.312  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.context.properties.EnableConfigurationPropertiesRegistrar.methodValidationExcludeFilter-----> postProcessBeforeInitialization
2022-11-27 22:07:40.312  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.context.properties.EnableConfigurationPropertiesRegistrar.methodValidationExcludeFilter ------> postProcessAfterInitialization
2022-11-27 22:07:40.313  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.context.LifecycleAutoConfiguration-----> postProcessBeforeInitialization
2022-11-27 22:07:40.313  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.context.LifecycleAutoConfiguration ------> postProcessAfterInitialization
2022-11-27 22:07:40.329  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: spring.lifecycle-org.springframework.boot.autoconfigure.context.LifecycleProperties-----> postProcessBeforeInitialization
2022-11-27 22:07:40.329  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: spring.lifecycle-org.springframework.boot.autoconfigure.context.LifecycleProperties ------> postProcessAfterInitialization
2022-11-27 22:07:40.330  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: lifecycleProcessor-----> postProcessBeforeInitialization
2022-11-27 22:07:40.330  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: lifecycleProcessor ------> postProcessAfterInitialization
2022-11-27 22:07:40.333  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: spring.info-org.springframework.boot.autoconfigure.info.ProjectInfoProperties-----> postProcessBeforeInitialization
2022-11-27 22:07:40.333  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: spring.info-org.springframework.boot.autoconfigure.info.ProjectInfoProperties ------> postProcessAfterInitialization
2022-11-27 22:07:40.334  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration-----> postProcessBeforeInitialization
2022-11-27 22:07:40.334  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration ------> postProcessAfterInitialization
2022-11-27 22:07:40.334  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration-----> postProcessBeforeInitialization
2022-11-27 22:07:40.334  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration ------> postProcessAfterInitialization
2022-11-27 22:07:40.336  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: spring.task.execution-org.springframework.boot.autoconfigure.task.TaskExecutionProperties-----> postProcessBeforeInitialization
2022-11-27 22:07:40.336  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: spring.task.execution-org.springframework.boot.autoconfigure.task.TaskExecutionProperties ------> postProcessAfterInitialization
2022-11-27 22:07:40.340  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: taskExecutorBuilder-----> postProcessBeforeInitialization
2022-11-27 22:07:40.340  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: taskExecutorBuilder ------> postProcessAfterInitialization
2022-11-27 22:07:40.341  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration-----> postProcessBeforeInitialization
2022-11-27 22:07:40.341  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration ------> postProcessAfterInitialization
2022-11-27 22:07:40.343  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: spring.task.scheduling-org.springframework.boot.autoconfigure.task.TaskSchedulingProperties-----> postProcessBeforeInitialization
2022-11-27 22:07:40.344  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: spring.task.scheduling-org.springframework.boot.autoconfigure.task.TaskSchedulingProperties ------> postProcessAfterInitialization
2022-11-27 22:07:40.345  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: taskSchedulerBuilder-----> postProcessBeforeInitialization
2022-11-27 22:07:40.345  INFO 12876 --- [           main] c.a.b.t.ExtendBeanPostProcessor          : beanName: taskSchedulerBuilder ------> postProcessAfterInitialization
2022-11-27 22:07:40.362  INFO 12876 --- [           main] c.a.b.BootSpringExtendApplication        : Started BootSpringExtendApplication in 0.822 seconds (JVM running for 2.124)

Process finished with exit code 0

小结

总结一下:

  1. BeanPostProcessors 册发生在容器启动的时候;自动注册BeanPostProcessors类型;
  2. 只要调用getBean始化对象都会触发BeanPostProcessors口的两个方法,并且是所有BeanPostProcessors例都会触发;
  3. 如果是FactoryBean型,容器不会帮我们自动初始化它产生的实例
    ,除非是SmartFactoryBean实例,并且它的isEagerlnit()返回的是true; IOC器才会也帮我们调用它的getobject放法来生成实例;

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/40619.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

InnoDB底层存储结构探秘

一 innoDB 为什么不用平衡二叉树 计算机存储层次结构 计算机存储设备一般分为两种&#xff1a;内存储器(main memory)和外存储器(external memory)。 内存储器为内存&#xff0c;内存存取速度快&#xff0c;但容量小&#xff0c;价格昂贵&#xff0c;而且不能长期保存数据(在…

动物大全和动物识别系统毕业设计,动物大全和动物AI识别系统设计与实现,动物识别系统论文毕设作品参考

功能清单 【后台管理员功能】 系统设置&#xff1a;设置网站简介、关于我们、联系我们、加入我们、法律声明 广告管理&#xff1a;设置小程序首页轮播图广告和链接 留言列表&#xff1a;所有用户留言信息列表&#xff0c;支持删除 会员列表&#xff1a;查看所有注册会员信息&a…

第七届NVIDIA Sky Hackathon项目报告书

系列文章目录 数据集收集和标注情况 1.1ASR语音数据集收集和标注情况 1.2CV图像数据集收集和标注情况进行模型的训练 2.1进行ASR模型的训练 2.2进行CV模型的训练在Jetson平台进行部署和推理 3.1部署和推理ASR模型 3.2部署和推理CV模型优化UI界面 文章目录系列文章目录1. 数据集…

详解BFS,Dijkstra算法,Floyd算法是如何解决最短路径问题的

目录 1.BFS算法 2.Dijkstra算法 3.Floyd算法 4.总结 1.BFS算法 G纲是个物流离散中心&#xff0c;经常需要往各个城市运东西&#xff0c;怎么运送距离最近——单源最短路径问题 各个城市之间也学要来往&#xff0c;相互之间怎么走距离最近&#xff1f;——每对顶点之间的最…

GNS3学习笔记

文章目录GNS3学习笔记一、GNS3支持的设备列表有哪些1、在安装根目录下 XXX\GNS3\appliances2、The NAT node 怎么使用二、GNS3使用错误汇总1、iosVL2 image(qemu平台)启动后进不去系统&#xff0c;一直重复进入开机界面三、参考链接1、GNS3应该使用那个模拟平台2、怎么集成VM到…

〖全域运营实战白宝书 - 运营角色认知篇⑧〗- 运营人的发展路径

大家好&#xff0c;我是 哈士奇 &#xff0c;一位工作了十年的"技术混子"&#xff0c; 致力于为开发者赋能的UP主, 目前正在运营着 TFS_CLUB社区。 &#x1f4ac; 人生格言&#xff1a;优于别人,并不高贵,真正的高贵应该是优于过去的自己。&#x1f4ac; &#x1f4e…

Flink源码解析(一、source原理)

文章目录背景逻辑原理connector架构sql处理阶段代码实例代码debug参考文献背景 source/sink 是flink最核心的部分之一&#xff0c;通过对其实现原理的学习&#xff0c;结合源码debug&#xff0c;有助于加深对框架处理过程的理解&#xff0c;以及架构设计上的提升。 逻辑原理 …

详细介绍 Oracle中的Materialized Views(物化视图/快照)

A materialized view (snapshot) is a table segment whose contents are periodically refereshed based on query (against a local or remote table)(针对的本地或者远程表) The simplest way to achieve replication of data between sites for against remote tables: ma…

中断上下文和进程上下文

中断上下文 参考博客&#xff1a;(https://blog.csdn.net/AndroidBBC/article/details/81911065) 中断上半部分&#xff0c;中断触发&#xff1b;中断下半部分&#xff0c;中断执行。 中断执行一般有tasklet、工作队列实现 工作队列机制 工作队列所执行的中断代码会表现出进…

Linux | 第一篇——常见指令汇总【超全、超详细讲解】

Linux之常见指令&#x1f333;前言&#x1f4bb;操作系统的概念&#x1f4bb;Linux的使用环境介绍&#x1f333;基本指令汇总一、【whoami】指令二、【pwd】指令三、【mkdir】指令四、【touch】指令五、【ls】指令1、拓展&#xff1a;文件的概念2、命令 - 命令选项六、【cd】指…

AtCoder Beginner Contest 260 G.Scalene Triangle Area(花式二维差分/二维线段树)

题目 n*n的网格(n<2e3)&#xff0c; 每个网格内的字符是O或者X&#xff0c;其中O表示(i,j)上有一个棋子&#xff0c;X表示没有 位于(s,t)棋子覆盖住了方格(u,v)&#xff0c;当且仅当&#xff1a; 1. 2. 3. q(q<2e5)次询问&#xff0c;第i次给出一个方格位置(xi…

如何给在 SAP Business Application Studio 里开发的 OData 服务准备测试数据试读版

在开始本步骤的学习之前&#xff0c;请大家务必完成前一步骤1. SAP Business Application Studio 里创建一个基于 CAP 模型的最简单的 OData 服务的学习。换言之&#xff0c;大家已经在 SAP Business Technology Platform 上的 Business Application Studio 里&#xff0c;创建…

Python实现基于Optuna超参数自动优化的xgboost回归模型(XGBRegressor算法)项目实战

说明&#xff1a;这是一个机器学习实战项目&#xff08;附带数据代码文档视频讲解&#xff09;&#xff0c;如需数据代码文档视频讲解可以直接到文章最后获取。 1.项目背景 Optuna是一个开源的超参数优化(HPO)框架&#xff0c;用于自动执行超参数的搜索空间。 为了找到最佳的超…

docker 部署多个前端vue项目

文章目录一、docker 部署前端项目方案1. 方案12. 方案2二、Nginx配置运行2.1. 拉取nginx镜像2.2. 创建配置目录2.3. 创建Nginx容器三、部署前端项目3.1. 压缩3.2. 上传3.3. 验证附录index.html50x.htmlnginx.conf一、docker 部署前端项目方案 1. 方案1 一个docker容器对应一个…

java中“冷门”工具类的总结

文章目录前言一些不常用的工具类不可变集合多值MapTable表Lists、Maps、Sets字符串操作BagLazyList双向Map并发集合小总结CopyOnWriteArrayListConcurrentHashMap前言 最近挖掘了一些在项目中不常用的工具类&#xff0c;有些实用性还是很高的&#xff0c;特此总结一下。 另外又…

mysql中的这些日志,你都知道吗 2?

上一篇文章&#xff0c;我们介绍了binlog和redo log这两种日志&#xff0c;对这两种日志不熟悉的老铁可以看下"mysql中的这些日志&#xff0c;你都知道吗",在上篇文章的末尾&#xff0c;作者还留了一个问题&#xff1a;binlog 和 redo log两个相互独立的日志模块&…

kube-ovn安装与卸载

1.环境准备 Kube-OVN 是一个符合 CNI 规范的网络组件&#xff0c;其运行需要依赖 Kubernetes 环境及对应的内核网络模块。 以下是通过测试的操作系统和软件版本&#xff0c;环境配置和所需要开放的端口信息。1.1 软件版本 Kubernetes > 1.16 且 < 1.24&#xff0c;推荐…

RK3568平台开发系列讲解(音频篇)Android AudioRecord 采集音频

🚀返回专栏总目录 文章目录 一、Android 平台的音频采集技术选型1.1、SDK 层提供的采集方法1.2、NDK 层提供的采集方法二、AudioRecord 采集音频沉淀、分享、成长,让自己和他人都能有所收获!😄 📢 Android 平台音频采集的技术选型,在 SDK 层和 NDK 层各有两套音频采集…

【MySQL】MySQL参数调优与实战详解(调优篇)(实战篇)(MySQL专栏启动)

&#x1f4eb;作者简介&#xff1a;小明java问道之路&#xff0c;专注于研究 Java/ Liunx内核/ C及汇编/计算机底层原理/源码&#xff0c;就职于大型金融公司后端高级工程师&#xff0c;擅长交易领域的高安全/可用/并发/性能的架构设计与演进、系统优化与稳定性建设。 &#x1…

dataloader重构与keras入门体验

原创文章第117篇&#xff0c;专注“个人成长与财富自由、世界运作的逻辑&#xff0c; AI量化投资”。 北京疫情昨天突破4000&#xff0c;社会面800。看来三天的预期过于乐观了&#xff0c;不知道如何发展。如同资本市场的短期走势&#xff0c;没有人可以预测。但往前看三年&am…