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基本概念)的更多相关文章

  1. 【Spring开发】—— Spring Core

    原文:[Spring开发]-- Spring Core 前言 最近由于一些工作的需要,还有自己知识的匮乏再次翻开spring.正好整理了一下相关的知识,弥补了之前对spring的一些错误认知.这一次学 ...

  2. Spring源码解析——核心类介绍

    前言: Spring用了这么久,虽然Spring的两大核心:IOC和AOP一直在用,但是始终没有搞懂Spring内部是怎么去实现的,于是决定撸一把Spring源码,前前后后也看了有两边,很多东西看了就 ...

  3. 多个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. ...

  4. Spring系列(零) Spring Framework 文档中文翻译

    Spring 框架文档(核心篇1和2) Version 5.1.3.RELEASE 最新的, 更新的笔记, 支持的版本和其他主题,独立的发布版本等, 是在Github Wiki 项目维护的. 总览 历 ...

  5. spring(一):spring的基础以及组件

    spring简介 spring是一种开源轻量级框架,是为了解决企业应用程序复杂性而创建的 spring是企业应用开发的“一站式”框架,致力于为javaEE应用的各层(表现层.业务层.持久层)开发提供解 ...

  6. 不要再说不会Spring了!Spring第一天,学会进大厂!

    工作及面试的过程中,作为Java开发,Spring环绕在我们的身边,很多人都是一知半解,本次将用14天时间,针对容器中注解.组件.源码进行解读,AOP概念进行全方面360°无死角介绍,SpringMV ...

  7. Spring是什么、spring容器、Spring三大核心思想DI(依赖注入)、IOC(控制反转)、AOP(面向切面编程)

    1.Spring (1)Spring是什么? 是一个轻量级的.用来简化企业级应用开发的开发框架. 注: a.简化开发: Spring对常用的api做了简化,比如,使用Spring jdbc来访问数据库 ...

  8. 关于spring.net的面向切面编程 (Aspect Oriented Programming with Spring.NET)-使用工厂创建代理(Using the ProxyFactoryObject to create AOP proxies)

    本文翻译自Spring.NET官方文档Version 1.3.2. 受限于个人知识水平,有些地方翻译可能不准确,但是我还是希望我的这些微薄的努力能为他人提供帮助. 侵删. 如果你正在为你的业务模型使用 ...

  9. Java实战之03Spring-03Spring的核心之AOP(Aspect Oriented Programming 面向切面编程)

    三.Spring的核心之AOP(Aspect Oriented Programming 面向切面编程) 1.AOP概念及原理 1.1.什么是AOP OOP:Object Oriented Progra ...

随机推荐

  1. P1309 瑞士轮 排序选择 时间限制 归并排序

    题目背景 在双人对决的竞技性比赛,如乒乓球.羽毛球.国际象棋中,最常见的赛制是淘汰赛和循环赛.前者的特点是比赛场数少,每场都紧张刺激,但偶然性较高.后者的特点是较为公平,偶然性较低,但比赛过程往往十分 ...

  2. 《第六周java学习笔记》

    教材知识点总结 Java 把 String 类定义为 final 类. new 运算符首先分配内存空间并在内存空间中放入字符序列,然后计算出引用.(new String(char a[],int st ...

  3. sql语句中start with用法,用于表达一个复杂的目录树存储在一张表中

    select * from tablename start with 条件1 connect by prior 条件2 where 条件3

  4. 在mybatis中调用存储过程的时候,不能加工语句

    select count(0) from ({call pkg_business.P_ZZS_LYFPHJSKJQK ('2018-04')}) 这是错误的.

  5. The Monocycle(bfs)

    题目描述: 转载自:https://blog.csdn.net/h1021456873/article/details/54572767 题意: 给你一个转轮,有5种颜色,为了5中颜色的位置是确定的, ...

  6. Windows10家庭版如何升级至Windows10专业版

    Windows10家庭版和专业版系统文件其实是一样的iso镜像文件,但是由于Microsoft某些限制导致一些用户无法享受到专业版的福利,说实话这是一种很让人蛋疼的操作... 接下来我来告诉各位如何把 ...

  7. hdu 1237 简单计算器 (表达式求值)【stack】

    <题目链接> 题目大意: 读入一个只包含 +, -, *, / 的非负整数计算表达式,计算该表达式的值.  Input测试输入包含若干测试用例,每个测试用例占一行,每行不超过200个字符, ...

  8. Redis自学笔记:2.准备

    第2章:准备 '纸上得来终觉浅,绝知此事要躬行'--陆游 2.2启动和停止redis 表2-1 redis可执行文件说明 文件名 说明 redis- server redis服务器 redis-cli ...

  9. 使用VSFTPD传输文件

    使用VSFTPD传输文件 一.文件传输协议 FTP(File Transfer Protocol)是一种在互联网进行文件传输的协议,基于B/S模式,默认使用20.21端口,其中20端口(数据端口)用于 ...

  10. 【开源GPS追踪】 之 服务器端opengts安装

    国内大多数GPS追踪/定位 平台都是基于opengts 二次开发的,opengts 是一款开源的gps 跟踪软件. 下面摘自百度百科: OpenGTS ™(“GPS跟踪系统”)是第一个可用的开源项目, ...