首页  

spring aop 代理对象生成     所属分类 spring 浏览量 888
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(String)



	protected Object getSingleton(String beanName, boolean allowEarlyReference) {
		Object singletonObject = this.singletonObjects.get(beanName);
		if (singletonObject == null && isSingletonCurrentlyInCreation(beanName)) {
			synchronized (this.singletonObjects) {
				singletonObject = this.earlySingletonObjects.get(beanName);
				if (singletonObject == null && allowEarlyReference) {
					ObjectFactory<?> singletonFactory = this.singletonFactories.get(beanName);
					if (singletonFactory != null) {
						singletonObject = singletonFactory.getObject();
						this.earlySingletonObjects.put(beanName, singletonObject);
						this.singletonFactories.remove(beanName);
					}
				}
			}
		}
		return singletonObject;
	}
	
public Object getSingleton(String beanName, ObjectFactory<?> singletonFactory) 




AbstractAutowireCapableBeanFactory#doCreateBean() 

1. createBeanInstance()   实例化Bean
2. populateBean()         填充属性
3. initializeBean()       初始化后的各种回调事件


后置处理器
BeanPostProcessor#postProcessAfterInitialization

AnnotationAwareAspectJAutoProxyCreator

org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.getEarlyBeanReference(Object, String)

org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(Object, String)


	@Override
	public Object postProcessAfterInitialization(@Nullable Object bean, String beanName) throws BeansException {
		if (bean != null) {
			Object cacheKey = getCacheKey(bean.getClass(), beanName);
			if (!this.earlyProxyReferences.contains(cacheKey)) {
				return wrapIfNecessary(bean, beanName, cacheKey);
			}
		}
		return bean;
	}

wrapIfNecessary 方法

createProxy 

getProxy

createAopProxy().getProxy()

两种代理实现
JDK  Cglib

JDK Proxy.newProxyInstance  
CGLIB  基于 ASM  

例子代码
https://gitee.com/dyyx/hellocode/blob/master/demo/springbootdemo/src/main/java/aop/Hello.java



spring如何解决循环依赖 AOP要点整理 基于Aspect注解的spring aop 实例 AOP知识点 AspectJ简介及实例

上一篇     下一篇
影响商业的50本书第11到19本

MBA商业黑话

H2 TCP server 模式

影响商业的50本书第20到29本

disruptor简介及核心概念

Disruptor 和 BlockingQueue 性能测试比较