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. POJ3074 Sudoku 舞蹈链 DLX

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目(传送门) 题意概括 给出一个残缺的数独,求解. 题解 DLX + 矩阵构建  (两个传送门) 代码 #include & ...

  2. 009 pandas的Series

    一:创建 1.通过Numpy数组创建 2.属性查看 3.一维数组创建(与numpy的创建一样) 4.通过字典创建 二:应用Numpy数组运算 1.获取值 numpy的数组运算,在Series中都被保留 ...

  3. TF之AE:AE实现TF自带数据集AE的encoder之后decoder之前的非监督学习分类—Jason niu

    import tensorflow as tf import numpy as np import matplotlib.pyplot as plt #Import MNIST data from t ...

  4. ACM-ICPC 2018 南京赛区网络预赛 L 【分层图最短路】

    <题目链接> 题目大意: 有N个城市,这些城市之间有M条有向边,每条边有权值,能够选择K条边 边权置为0,求1到N的最短距离. 解题分析: 分层图最短路模板题,将该图看成 K+1 层图,然 ...

  5. 说说nginx,iis,apache,tomcat

    一.nginx ngnix是反向代理服务器,它是代理,本身并不执行,是个传话筒,把用户提交的请求转发给web服务器,再把web服务器的结果转发给用户.为了提高性能,启用反向代理,实际的web服务器可以 ...

  6. POJ1700----Crossing River

    #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> us ...

  7. 潭州课堂25班:Ph201805201 django 项目 第三十三课 后台文章标签查询提交到前台,删除功能实现(课堂笔记)

    在视图中创建个类,要实现此功能,并把结果返回前台 , from django.shortcuts import render from django.views import View from dj ...

  8. Vue.Js初学踩坑

    1 Vue2之后取消了v-bind的.sync修饰符,意味着父子组件的数据不能以此来实现双向绑定. 2 Vue2之后取消了filterBy过滤器,所以以下这种用法是错误的了. <tbody> ...

  9. 秘密袭击 [BZOJ5250] [树形DP]

    分析: 听说正解是FFT+线段树合并,然而我并不会... 我们来思考其他的方法. 我们要求的是连通块第k大的和 对于某一个连通块,对答案的贡献=val(Rank.K) 我们不好直接算出每个连通块的Ra ...

  10. 快速排序 [Qsort]

    在做USACO1.4 等差数列的时候,我发现如果用结构体+sort就会超时,用二维数组+qsort就能AC,所以为了不忘记Quick Sort,我还是把代码贴出来以备以后要看吧. void qsort ...