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

 picture
image-20210913072321674

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

 picture
image-20210910074335232

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

 picture
image-20210910073611972

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

 picture
image-20210910074649844

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 .

 picture
image-20210910081828619

Tangent expression graph

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

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

 picture
image-20210910082639157

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

 picture
image-20210913074020835

The following is the focus of this article ~

programmatic AOP

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

 picture
image-20210912074920354

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

Pointcut

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

 picture
image-20210912100228554

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

 picture
AOP_Pointcut

effect

You can see that only enhanced setName Method

 picture
image-20210912094544020

Advice

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

 picture
image-20210912161447604

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

 picture
image-20210912104757851

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

Advisor

effect

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

Advised

effect

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

JDK

 picture
image-20210911231149301

Cglib

 picture
image-20210911233943416

Conclusion

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

 picture
SpringAOP

Last

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 !

https://github.com/Java4ye/springboot-demo-4ye/tree/main/springboot-aop

Mind mapping

http://processon.com/chart_image/6134d6cb7d9c081c753b5d54.png

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

 picture
image-20210913074314344

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 !!


版权声明
本文为[Java4ye]所创,转载请带上原文链接,感谢
https://javamana.com/2021/10/20211002145641037d.html

  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