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 ...
随机推荐
- java的IO流的一些测试
public class Demo02 { public static void main(String[] args) { //获取当前毫秒值,用于测试 long l = System.curren ...
- C++实现--最大公因数和最小公倍数
一丶 最大公因数求法: 辗转相除法(也称欧几里得算法)原理: 二丶最小公倍数求法:两个整数的最小公倍数等于两整数之积除以最大公约数 C++ 代码实现 #include <iostream ...
- git checkout 撤销多个文件,撤销整个文件夹
git checkout 撤销多个文件,撤销整个文件夹 git checkout <folder-name>/ git checkout -- <folder-name> 这样 ...
- js里面的判断最好做到完全控制
<li class="item"> <div id="zcdz" name="zcdz" class="mini ...
- hdu1202解题报告
#include<stdio.h>int main(){ int n,i; double sum,s,p,sum1; while(scanf("%d" ...
- JAVA项目中常用的异常处理情况
1.数学运算异常( java.lang.arithmeticexception) 程序中出现了除以零这样的运算就会出这样的异常,对这种异常,大家就要好好检查一下自己程序中涉及到数学运算的地方,公式是不 ...
- gradle修改apk包名和apk文件名
需求1:根据渠道不同给包名添加不同的后缀名 方案: //先定义默认包名,用来复用 def packageName = "xxx.xxxx.xxxx" defaultConfig { ...
- POJ2387 Til the Cows Come Home 【Dijkstra】
题目链接:http://poj.org/problem?id=2387 题目大意; 题意:给出两个整数T,N,然后输入一些点直接的距离,求N和1之间的最短距离.. 思路:dijkstra求单源最短路, ...
- MySQL Unable to convert MySQL datetime value to System.DateTime 解决方案
Unable to convert MySQL date/time value to System.DateTime 解决方案 这个问题发生在MySQL数据里面有Date类型数据,在C#中查询出来时候 ...
- Django——支付宝支付功能
前期准备 首先我们需要获得支付宝提供的权限与接口,在蚂蚁开放平台进行相关申请:https://openhome.alipay.com/platform/appDaily.htm?tab=info 申请 ...