Spring Core Programming(Spring核心编程) - AOP Concepts(AOP基本概念)
1. What is aspect-oriented programming?
(什么是面向切面编程?)
Aspects help to modularize cross-cutting concerns.
(切面帮助我们模块化横切关注点)
In short, a cross-cutting concern can be described as any functionality that affects multiple points of an application.
(简单来说, 一个横切关注点可以理解为任何影响某个应用程序的功能,这个功能会从一些切入点进入程序)
For example, security is a cross-cutting concern, we cam apply security rules to many methods in an application by AOP.
(举例来说, 安全就是一个横切关注点, 我们可以用过AOP的方式给应用中的许多方法增加安全逻辑)
The below picture can help us understand AOP more intuitively
(下图可以帮助我们更加直观地理解AOP编程)

2. The benefits of AOP
(AOP的好处)
With AOP, you can define the common functionality in one place,
(通过AOP, 你可以在一个地方定义通用功能)
but you can define how and where this functionality is applied without having to modify the class
to which you’re applying the new feature, thus the class can focus on its main logic.
(你可以通过定义如何并且在何处应用该功能,而不用修改要被影响的那个类,这样被应用的类可以关注它的主逻辑)
3. Some core concepts of AOP
(AOP的一些核心概念)
Below are the important terminologies of aspects:
(以下是一些切面的重要术语)
advice(通知) / pointcuts(切点) / join points(连接点)
直观如如下:

3-1) advice(通知)
The job of an aspect is called advice,
(通知其实就是切面的工作)
it defines what and when of an aspect.
(它定义了这个切面干什么的,以及何时使用)
Spring aspects can work with five kinds of advice:
(Spring中可以有5种类型的通知)
* Before(前置通知)
— The advice functionality takes place before the advised method is invoked.
(在目标方法被调用之前调用)
* After(后置通知)
— The advice functionality takes place after the advised method completes, regardless of the outcome.
(在目标方法完成之后调用, 不关心方法的输出)
* After-returning(返回通知)
— The advice functionality takes place after the advised method successfully completes.
(在目标方法成功执行之后调用)
* After-throwing(异常通知)
— The advice functionality takes place after the advised method throws an exception.
(在目标方法抛出异常后调用)
* Around(环绕通知)
— The advice wraps the advised method, providing some functionality before and after the advised method is invoked.
(包裹目标方法, 在目标方法调用之前和调用之后都要调用)
3-2) JOIN POINTS(切点)
A join point is a point in the execution of the application where an aspect can be plugged in.
(连接点是在应用执行过程中插入的点)
could be a method being called, an exception being thrown, or even a field being modified
(可以使调用方法时, 异常抛出时, 或者甚至是一个字段被修改时)
3-3) POINTCUTS(切点)
If advice defines the what and when of aspects, then pointcuts define the where.
(如果说通知定义了切面的什么和何时的话,那么切点定义了切面的何处)
Specify pointcuts using explicit class and method names
or through regular expressions that define matching class and method name patterns.
(通过制定类和方法名,或者正则表达式指定的类和方法名称来指定切点)
4. SPRING ADVISES OBJECTS AT RUNTIME
(Spring在运行时通知对象)
In Spring, aspects are woven into Spring-managed beans at runtime by wrapping them with a proxy class.
(通过在代理类中包裹切面, Spring在运行时把切面织人到Spring管理的类中)
如下图:

Spring Core Programming(Spring核心编程) - AOP Concepts(AOP基本概念)的更多相关文章
- 【Spring开发】—— Spring Core
原文:[Spring开发]-- Spring Core 前言 最近由于一些工作的需要,还有自己知识的匮乏再次翻开spring.正好整理了一下相关的知识,弥补了之前对spring的一些错误认知.这一次学 ...
- Spring源码解析——核心类介绍
前言: Spring用了这么久,虽然Spring的两大核心:IOC和AOP一直在用,但是始终没有搞懂Spring内部是怎么去实现的,于是决定撸一把Spring源码,前前后后也看了有两边,很多东西看了就 ...
- 多个IoC容器适配器设计及性能测试(Castle.Windsor Autofac Spring.Core)
[转]多个IoC容器适配器设计及性能测试和容器选择 1. 采用的IoC容器和版本 Autofac.2.6.3.862 Castle.Windsor.3.1.0 Spring.Core.2.0.0 2. ...
- Spring系列(零) Spring Framework 文档中文翻译
Spring 框架文档(核心篇1和2) Version 5.1.3.RELEASE 最新的, 更新的笔记, 支持的版本和其他主题,独立的发布版本等, 是在Github Wiki 项目维护的. 总览 历 ...
- spring(一):spring的基础以及组件
spring简介 spring是一种开源轻量级框架,是为了解决企业应用程序复杂性而创建的 spring是企业应用开发的“一站式”框架,致力于为javaEE应用的各层(表现层.业务层.持久层)开发提供解 ...
- 不要再说不会Spring了!Spring第一天,学会进大厂!
工作及面试的过程中,作为Java开发,Spring环绕在我们的身边,很多人都是一知半解,本次将用14天时间,针对容器中注解.组件.源码进行解读,AOP概念进行全方面360°无死角介绍,SpringMV ...
- Spring是什么、spring容器、Spring三大核心思想DI(依赖注入)、IOC(控制反转)、AOP(面向切面编程)
1.Spring (1)Spring是什么? 是一个轻量级的.用来简化企业级应用开发的开发框架. 注: a.简化开发: Spring对常用的api做了简化,比如,使用Spring jdbc来访问数据库 ...
- 关于spring.net的面向切面编程 (Aspect Oriented Programming with Spring.NET)-使用工厂创建代理(Using the ProxyFactoryObject to create AOP proxies)
本文翻译自Spring.NET官方文档Version 1.3.2. 受限于个人知识水平,有些地方翻译可能不准确,但是我还是希望我的这些微薄的努力能为他人提供帮助. 侵删. 如果你正在为你的业务模型使用 ...
- Java实战之03Spring-03Spring的核心之AOP(Aspect Oriented Programming 面向切面编程)
三.Spring的核心之AOP(Aspect Oriented Programming 面向切面编程) 1.AOP概念及原理 1.1.什么是AOP OOP:Object Oriented Progra ...
随机推荐
- day23 面向对象 函数和方法区分
最近两周内容大概回顾: # 文件操作 # # 模块:random,序列化模块,时间模块,collections,re,os,sys # 模块与包的概念和导入方法 # 写代码的规范 # 正则表达式 # ...
- 20165220 2017-2018-2《Java程序设计》课程总结
每周作业链接汇总: 20165220 我期望的师生关系 20165220 学习基础和C语言基础调查 20165220 Linux安装及学习 20165220 第一周学习总结 20165220 第二周学 ...
- VC9、VC11、VC14、VC15库 32位 64位 免费下载
VC9.VC11.VC14.VC15库 32位 64位 免费下载 更新版本的PHP是用VC11,VC14或VC15(分别为Visual Studio 2012,2015或2017编译器)构建的,并且包 ...
- HDU 1054 Strategic Game (最小点覆盖)【二分图匹配】
<题目链接> 题目大意:鲍勃喜欢玩电脑游戏,特别是战略游戏,但有时他无法找到解决方案,速度不够快,那么他很伤心.现在,他有以下的问题.他必须捍卫一个中世纪的城市,形成了树的道路.他把战士的 ...
- LOJ.6068.[2017山东一轮集训Day4]棋盘(费用流zkw)
题目链接 考虑两个\(\#\)之间产生的花费是怎样的.设这之间放了\(k\)个棋子,花费是\(\frac{k(k-1)}{2}\). 在\((r,c)\)处放棋子,行和列会同时产生花费,且花费和该行该 ...
- Codeforces.666E.Forensic Examination(广义后缀自动机 线段树合并)
题目链接 \(Description\) 给定串\(S\)和\(m\)个串\(T_i\).\(Q\)次询问,每次询问\(l,r,p_l,p_r\),求\(S[p_l\sim p_r]\)在\(T_l\ ...
- 生产者与消费者 代码实现 java
首先,我利用忙测试写出了第一次版本的代码 package How; //自写代码 缺陷 无法完全实现pv操作线程处于忙测试状态 public class bin_1_1 { public static ...
- mongodb副本集出现的错误 mongodb error: { MongoNetworkError: failed to connect to server [127.0.0.1:1010] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:1010]
replset = pictureWorks 执行:mongo --port 1008 (查看1008是否是住数据库) rs.status() 执行: onfig={"_id": ...
- js点击回到顶部2
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>点 ...
- 使用纯CSS制作展开合并立方体特效
显示效果 源码 <html> <head> <meta http-equiv="Content-Type" content="text/ht ...