AOP of spring source code

newbaby2012 2022-02-13 08:17:53 阅读数:310

aop spring source code


Spring AOP Second packaging practice , Interview Ali 50W Necessary skills for annual salary post ( Including programmer career explanation )_ Bili, Bili _bilibili

Annotation opening process diagram

 AbstractAutoProxyCreator The inheritance diagram of

Note that it inherits InstantiationAwareBeanPostProcessor Interface

All interceptors implement Advice Interface , Or a Advice object , such as MethodAdvice

The proxy object passes through addAdvice To add interceptors , When you call a proxy object method, you first call MethodBeforeAdvice Of before Method

aop xml context Configure interceptors

Handwriting spring mvc

  Put commonly used variables into the cache Map in

Learn first xml Version of spring Source code

Have a look addAdvice Method

processon Have a look AOP and IOC Mind maps

How to solve circular dependency earlySingletonExposure

spring Three level cache , Have a look singletonObjects

Is learning source code for secondary expansion ?


Spring Complete collection of underlying source code analysis videos 2020 The latest product in _ Bili, Bili _bilibili

springboot Is based on annotations ? No xml

At the beginning of looking at the source code, it depends on the return value

therefore spring getbean Returned object , Are they all proxy objects ??

beforeSingletonCreation There's a what ?

resolveBeforeInstantiation Create proxy object   Place the cache , profiling aspect ?  But the premise is that there must be an object

So the actual proxy object is , stay initializeBean Of applyBeanPostProcessorAfterInitialization In the method

But this · Must have EnableAspectAutoProxy annotation

At the beginning of the screenshot !! The back should also

In every way ?

Reference resources  spring Source code 1_AOP_ Enjoy learning _qq_53294028 The blog of -CSDN Blog

There are three steps to generate the section :

1. Config Class add  @EnableAspectJAutoProxy, Put business logic and aspect classes in it

public class Cap10MainConfig {
public Calculator calculator(){
return new Calculator();
public LogAspects logAspects(){
return new LogAspects();

2. adopt @Aspect Declare the facet class , And define... In the section class pointCut and Before,After etc.

// Log facet class
public class LogAspects {
@Pointcut("execution(public int com.enjoy.cap10.aop.Calculator.*(..))")
public void pointCut(){};
//@before Represents a cut in... Before the target method is executed , And specify before which method to cut in
public void logStart(){
System.out.println(" Division operation .... The parameter list is :{}");

3. Business class

public class Calculator {
// Business logic approach
public int div(int i, int j){
return i/j;

AOP flow chart ( To be improved )

transaction flow chart ( Copied online )



Write for yourself ,ioc aop transaction

copyright:author[newbaby2012],Please bring the original link to reprint, thank you.