Spring AOP internal skill cultivation

Java4ye 2021-10-14 06:59:26
spring aop internal skill cultivation

ha-ha Finally here

Today, let's share this with our friends Spring AOP   Knowledge points of


Here I recommend you to read Spring Official documents of ,core Document 5,6 chapter , and AOP Related concepts can be found here ~, And what we need to know Spring AOP APIs


Let's introduce this AOP

AOP Concept

This is an old question ha-ha Familiar friends can skip

Section oriented programming Aspect-Oriented Programming , It's right OOP A supplement to

The usage scenarios are : journal , Business , Permission authentication , cache etc.

and Spring AOP Well , It will go through this proxy class To implement the method enhance


Here are some important concepts ( Just look at the picture )


Concept diagram

adopt PointCut To match matching JoinPoint , Do it again Weaving· operation , take  Advice Weave into it .

and PointCut and Advice Store in Aspect   in .


Tangent expression graph

Such as :execution ,within , this ,target ,args ,bean

as well as Match annotation With @target ,@args ,@within , @annotation


Advice Annotation diagram

Here are five common annotations

Be careful :@After be equal to finally Sentence block , It must be carried out , also @Around When the annotation , The first parameter of the method must be ProceedingJoinPoint , It is JoinPoint Sub interface of


The following is the focus of this article ~

programmatic AOP

How about this one , We wrote AOP plug-in unit The basis of


Here we need to understand these concepts

  • Pointcut :   Corresponding @Pointcut
  • Advice Corresponding @Before,@After,@Around wait
  • Advisor@Aspect Annotation parsed class , be equal to Pointcut + Advice
  • Advised :   Spring AOP Proxy classes can be converted to this interface !

Example I put Github Come on , The address is at the end of the text


There are two return types  ClassFilter and  MethodMatcher   Methods , Their functions are as follows


4ye It's also about understanding ha-ha Mainly with Spring Implementation class provided , As used in the following example NameMatchMethodPointcut , You can guess by name , It matches the method name

Small example

There are many code examples , Here's one Pointcut   Just have a look ~  ( Other case codes can be found on my own Github Get from warehouse )

Through to ProxyFactroy add to section To the target sayService Do increase , there Pointcut Only aim at setName Method



You can see that only enhanced setName Method



You can see here Spring Provides this Five types . Except for the last one Introduction The type is not mentioned above , Is there another type missing


you 're right , This is this. @After The notes correspond to Final notice

Where have you been ( ̄﹏ ̄;)

After looking in the source code , Found this AspectJAfterAdvice


You can see that not only is it realized here AfterAdvice   Interface , And realize this MethodInterceptor Interface , Finally, really in finally This is implemented in the statement block Enhanced operation , In order to achieve Final notice The effect of !

So we need Final notice In terms of effect , Just imitate it directly ~

and Introduction Advice This is quite special

effect : Implement a new interface for the proxy class

be equal to @DeclareParents annotation



@Aspect Annotation parsed class , be equal to Pointcut + Advice



AOP Proxy classes can be converted to this interface

Why can these proxy objects be converted to this Advised Interface ?

Of course, the answer is self-evident ha-ha , Let's look at the source code Spring How is it written






You can find , Whether it's JDK still Cglib , Will call the same method , Implement several more interfaces for the proxy class , One of them is Advised

The diagram



So much for this article

The key content is programmatic AOP   This piece of ~ Internal skill +1

The code can be obtained here   You can run more code yourself , There will be more problems waiting for you to find out !


Mind mapping


ps: It actually appeared when sharing this time Gateway Timeout abnormal , If you can't wait for the official repair , It can be obtained on the network disk

link :https://pan.baidu.com/s/1KVWw0DaYCKrISIKJgqqyuA

Extraction code Need to reply in official account background. bdwp


I also uploaded part of the code of the plug-in , I need to draw and write ha-ha ( These two days should be arranged )

If you like, you can Focus on and Star standard Next official account Java4ye Under the support 4ye ah , In this way, you can receive more information at the first time

I am a 4ye We should …… See you soon !!


  1. Day17 Java Foundation
  2. Day18 Java Foundation
  3. Linux installe JDK 1.8 et configure les variables d'environnement
  4. Tutoriel d'utilisation Maven super détaillé
  5. Spring boot reads project parameter configuration
  6. Docker installing rocketmq
  7. Java Zero Basic small white Beginner must make a summary of issues (recommended Collection) Chapitre 1
  8. Manuel pour vous apprendre à utiliser le développement Java pour générer des documents PDF en ligne
  9. 40 + comment les femmes s'habillent - elles pour montrer leur jeunesse?Un manteau et une jupe vous donnent un look haut de gamme tout au long de l'automne et de l'hiver
  10. Tutoriel d'installation Ubuntu 16.04 / Hadoop 3.1.3Configuration autonome / pseudo - distribuée
  11. L'apprentissage le plus détaillé de springboot à l'échelle du réseau - day01
  12. L'apprentissage le plus détaillé de springboot sur le Web - day02
  13. L'apprentissage le plus détaillé de springboot sur le Web - day03
  14. L'apprentissage le plus détaillé de springboot sur le Web - day04
  15. Tutoriel d'utilisation Maven super détaillé
  16. L'apprentissage le plus détaillé de springboot sur le Web - day05
  17. L'apprentissage le plus détaillé de springboot sur le Web - day06
  18. L'apprentissage le plus détaillé de springboot sur le Web - day07
  19. Introduction to JavaScript - write a photo album for your girlfriend
  20. [Hadoop 3. X] HDFS storage type and storage strategy (V) overview
  21. L'apprentissage le plus détaillé de springboot sur le Web - day08
  22. Introduction à la page Web de rabbitmq (3)
  23. No Converter found for return value of type: class java.util.arraylist Error Problem
  24. (16) , spring cloud stream message driven
  25. Que faut - il apprendre de l'architecture des microservices Spring Cloud?
  26. Résolution: erreur: Java: distribution cible invalide: 11problème d'erreur
  27. Springboot démarre en une minute et sort de l'enfer de la configuration SSM!
  28. Maven - un outil de gestion essentiel pour les grands projets d'usine, de l'introduction à la maîtrise![️ Collection recommandée]
  29. ️ Push to interview in Large Factory ᥧ - - Spring Boot Automatic Assembly Principle
  30. [️ springboot Template Engine] - thymeleaf
  31. Springboot - MVC Automatic configuration Principle
  32. Mybatis reverse engineering and the use of new version mybatisplus 3.4 reverse engineering
  33. Base de données MySQL - transactions et index
  34. Sécurité du printemps - [authentification, autorisation, déconnexion et contrôle des droits]
  35. Moteur de base de données InnoDB diffère de myisam
  36. Swagger - [springboot Integrated Swagger, configure Swagger, configure scan Interface, configure API Group]
  37. Cadre de sécurité Shiro - [QUICKstart, login Block, User Authentication, request Authorization]
  38. [Introduction à Java] installation de l'environnement de développement - Introduction à Java et construction de l'environnement
  39. 【 linux】 notes d'utilisation tmux
  40. MySQL + mybatis paging query - database series learning notes
  41. Usage relations and differences of count (1), count (*) and count (a field) in MySQL
  42. 2021 Ali Java advanced interview questions sharing, Java Architect interview materials
  43. Mybatis - dynamic SQL statement - if usage - MySQL series learning notes
  44. [go to Dachang series] deeply understand the use of where 1 = 1 in MySQL
  45. [secret room escape game theme ranking list] Based on spring MVC + Spring + mybatis
  46. Redis log: the killer mace of fearless downtime and rapid recovery
  47. 5 minutes to build redis cluster mode and sentinel mode with docker
  48. Java小白入门200例106之遍历ArrayList的几种方式
  49. Java小白入门200例105之Java ArrayList类
  50. Java小白入门200例104之JDK自带记录日志类logging
  51. Practice of high availability architecture of Tongcheng travel network based on rocketmq
  52. Chapter 9 - Linux learning will - file archiving and compression tar --- zip
  53. Java小白入門200例104之JDK自帶記錄日志類logging
  54. JDK avec journalisation de classe dans 200 cas 104
  55. Java ArrayList Class for Introduction to Java LITTLE WHITE 200 example 105
  56. Plusieurs façons de traverser ArrayList à partir de 200 exemples 106
  57. Provectus / Kafka UI: open source Apache Kafka's Web GUI Graphical interface management tool
  58. Design pattern series: Singleton pattern
  59. Java小白入門200例105之Java ArrayList類
  60. Understanding Java record types