Spring aop Introduction
Aspect-Oriented Programming (AOP) complements Object-Oriented Programming (OOP) by providing another way of thinking about program structure. The key unit of modularity in OOP is the class, whereas in AOP the unit of modularity is the aspect. Aspects enable the modularization of concerns such as transaction management that cut across multiple types and objects. (Such concerns are often termed crosscutting concerns in AOP literature.)
One of the key components of Spring is the AOP framework. While the Spring IoC container does not depend on AOP, meaning you do not need to use AOP if you don't want to, AOP complements Spring IoC to provide a very capable middleware solution.
AOP is used in the Spring Framework to...
... provide declarative enterprise services, especially as a replacement for EJB declarative services. The most important such service is declarative transaction management.
... allow users to implement custom aspects, complementing their use of OOP with AOP.
If you are interested only in generic declarative services or other pre-packaged declarative middleware services such as pooling, you do not need to work directly with Spring AOP, and can skip most of this chapter.
Spring aop 介绍
AOP编程通过另一种关于编程架构的思考,补充了OOP的编程方式。OOP的主要元素是类,而AOP的主要元素是切面。切面将贯穿于多个类型和对象之间的事务管理等类似的问题进行了模块化。(这些问题通常在AOP的资料中定义为关注切面问题)
Spring的一个关键组件是AOP框架。但是Spring的Ioc容器并没有依赖于AOP,这就意味着如果你不想用AOP,那么你就不需要用AOP,AOP只是为IOC提供了一种非常强大的中间件解决方案。
AOP在Spring框架中有如下用途:
提供声明式企业服务,特别是替代了EJB的声明服务。最主要的就是想声明式事务管理这样的服务。
允许用户实现自定义的切面,从而通过AOP完善自己的OOP使用。
如果你只对通用的声明式服务或者其他的欲打包声明式中间件服务(如pooling),那么你不需要直接与Spring AOP产生直接关系,而且可以略过这一章的大部分内容。