zoukankan      html  css  js  c++  java
  • Spring AOP简介

    AOP简述

    AOP的概念早在上个世纪九十年代初就已经出现了,当时的研究人员通过对面向对象思想局限性的分析研究出了一种新的编程思想来帮助开发者减少代码重复提高开发效率,那就是AOP,Aspect-Oriented Programming。AOP是OOP的补充,是GOF的延续。我们知道设计模式是对于面向对象设计中经验的总结,它孜孜不断追求的就是调用者与被调用者之间的解耦。有了设计模式我们可以更有效的利用面向对象的特性,使得整个软件设计更加灵活、优雅。但是设计模式是基于面向对象的思想而形成的,更多的时候关注的是对象层次的东西,在解决对象行为内部问题方面却有些不足。AOP的出现恰恰就是对面向对象思想做出了完美的补充。

    上图显示了软件的纵向和横向结构,从纵向结构来看就是我们软件系统的各个模块,它主要负责处理我们的核心业务(例如商品订购、购物车查看);而从横向结构来看,我们几乎每个系统又包含一些公共模块(例如权限、日志模块等)。这些公共模块分布于我们各个核心业务之中(例如订购和查看商品明细的过程都需要检查用户权限、记录系统日志等)。这样一来不仅在开发过程中要处处关注公共模块的处理而且开发后维护起来也是十分麻烦。而有了AOP之后将应用程序中的商业逻辑同对其提供支持的通用服务进行分离,使得开发人员可以更多的关注核心业务开发。

    基本概念:

    Let us begin by defining some central AOP concepts and terminology. These terms are not Spring-specific…​ unfortunately, AOP terminology is not particularly intuitive; however, it would be even more confusing if Spring used its own terminology.

    • Aspect: a modularization of a concern that cuts across multiple classes. Transaction management is a good example of a crosscutting concern in enterprise Java applications. In Spring AOP, aspects are implemented using regular   classes (the schema-based approach) or regular classes annotated with the @Aspectannotation (the @AspectJ style).
    • Join point: a point during the execution of a program, such as the execution of a method or the handling of an exception. In Spring AOP, a join point alwaysrepresents a method execution.
    • Advice: action taken by an aspect at a particular join point. Different types of advice include "around," "before" and "after" advice. (Advice types are discussed below.) Many AOP frameworks, including Spring, model an advice as   an interceptor, maintaining a chain of interceptors around the join point.
    • Pointcut: a predicate that matches join points. Advice is associated with a pointcut expression and runs at any join point matched by the pointcut (for example, the execution of a method with a certain name). The concept of join  points as matched by pointcut expressions is central to AOP, and Spring uses the AspectJ pointcut expression language by default.
    • Introduction: declaring additional methods or fields on behalf of a type. Spring AOP allows you to introduce new interfaces (and a corresponding implementation) to any advised object. For example, you could use an introduction to make a bean implement an IsModified interface, to simplify caching. (An introduction is known as an inter-type declaration in the AspectJ community.)
    • Target object: object being advised by one or more aspects. Also referred to as the advised object. Since Spring AOP is implemented using runtime proxies, this object will always be a proxied object.
    • AOP proxy: an object created by the AOP framework in order to implement the aspect contracts (advise method executions and so on). In the Spring Framework, an AOP proxy will be a JDK dynamic proxy or a CGLIB proxy.
    • Weaving: linking aspects with other application types or objects to create an advised object. This can be done at compile time (using the AspectJ compiler, for example), load time, or at runtime. Spring AOP, like other pure Java   AOP frameworks, performs weaving at runtime.
  • 相关阅读:
    高校手机签到系统——Ksoap2的一些使用心得(补充)
    高校手机签到系统——zxing.net生成二维码(补充)
    高校手机签到系统——手机客户端
    高校手机签到系统——第一部分Authority权限系统(下)
    高校手机签到系统——第一部分Authority权限系统(上)
    《算法导论》——顺序统计RandomizedSelect
    《算法导论》——计数排序Counting Sort
    [Asp.Net Core] Blazor Server Side 项目实践
    [Asp.Net Core] Blazor Server Side 开发教程
    视频图文教学
  • 原文地址:https://www.cnblogs.com/gy19920604/p/5217128.html
Copyright © 2011-2022 走看看