引入:aop scheme。
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
需明确的几个概念: 通知(Advice):用于告知系统将有哪些新的行为。 切入点(Pointcut):定义了通知应该在应用到那些连接点。 目标对象(Target):被通知的对象。 代理(Proxy):将通知应用到目标对象后创建的对象。
需明确的几个概念:
l 通知(Advice):用于告知系统将有哪些新的行为。
l 切入点(Pointcut):定义了通知应该在应用到那些连接点。
l 目标对象(Target):被通知的对象。
l 代理(Proxy):将通知应用到目标对象后创建的对象。
Spring有两种代理创建方式:
1. 如果目标对象实现了一个或多个接口暴露的方法,Spring将使用JDK的java.lang.reflect.Proxy创建代理。这个类让Spring动态产生一个新的类,它实现了所需的接口,织入了通知,并且代理目标的所有请求。(这篇主要介绍这个方式)
2. 如果目标对象没有实现任何接口,Spring使用CGLIB库生成目标对象的子类。在创建这个子类的时候,Spring将通知织入,并且将对目标对象的调用委托给这个子类。
本文介绍了Spring框架中AOP(面向切面编程)的基本概念,包括通知、切入点、目标对象和代理等核心组成部分。同时详细讲解了Spring创建代理的两种方式:基于JDK动态代理和CGLIB子类代理。
256

被折叠的 条评论
为什么被折叠?



