Giter Site home page Giter Site logo

Spring源码之AOP的实现方式 about project HOT 2 OPEN

zyllt avatar zyllt commented on August 11, 2024
Spring源码之AOP的实现方式

from project.

Comments (2)

zyllt avatar zyllt commented on August 11, 2024

1、基于注解的,需要配置aspectj-autoproxy;

2、还有一种是基于XML文件的,需要配置config,advisor等

from project.

zyllt avatar zyllt commented on August 11, 2024

第一种是在解析的时候会注册一个AspectJAwareAdvisorAutoProxyCreator,这个类继承自InstantiationAwareBeanPostProcessor的,具体对被注入了AOP的bean在实例化之前会调用AbstractAutoProxyCreator#postProcessBeforeInstantiation,在此中会生成代理对象。
如果配置了proxy-target-class=true或者该类没有接口,使用cglib来生成一个子类。如果为false并且有接口则使用jdk的proxy

		if (beanName != null) {
			TargetSource targetSource = getCustomTargetSource(beanClass, beanName);
			if (targetSource != null) {
				this.targetSourcedBeans.add(beanName);
				Object[] specificInterceptors = getAdvicesAndAdvisorsForBean(beanClass, beanName, targetSource);
				Object proxy = createProxy(beanClass, beanName, specificInterceptors, targetSource);
				this.proxyTypes.put(cacheKey, proxy.getClass());
				return proxy;
			}
		}

from project.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.