1. 什么是AOP
AOP(Aspect Orient Programming),面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术。AOP是OOP的延续,是软件开发中的热点,也是Spring框杂中的一个重要内容,是函数式编程的一种衍生。
2. 为什么需要AOP
利用AOP可以对业务逻辑的各个部分进行 隔离,从而使得业务逻辑各部分之间的 耦合度降低,提高程序的可重用性,同时提高开发效率。
3. 注入框架
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.7</version>
</dependency>
4.xml方式面向切面编程
- 注入Bean(定义完接口和实现类后,需要在applicationContext.xml注入Bean)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework