目錄
一、Spring-AOP。
(1)AOP的簡介。?
(2)AOP的底層實(shí)現(xiàn)-動態(tài)代理。?
(2.1)JDK的動態(tài)代理。
?(2.2)cglib的動態(tài)代理。
?(3)AOP的相關(guān)概念。?
(4)xml配置——AOP的快速入門。
(5) xml配置AOP詳解。
(5.1)切點(diǎn)表達(dá)式的寫法。?
(5.2)通知的類型。
(5.3)切點(diǎn)表達(dá)式的抽取。
(5.4)知識要點(diǎn)。
(6)注解配置——AOP的快速入門。
(7)注解配置AOP詳解。
(7.1)注解通知的類型。
?(7.2)切點(diǎn)表達(dá)式的抽取。
(7.3)?知識要點(diǎn)。?
一、Spring-AOP。
(1)AOP的簡介。?
(2)AOP的底層實(shí)現(xiàn)-動態(tài)代理。?
(2.1)JDK的動態(tài)代理。
?(2.2)cglib的動態(tài)代理。
?(3)AOP的相關(guān)概念。?
(4)xml配置——AOP的快速入門。
<?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:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<!--1、目標(biāo)對象-->
<bean id="target" class="aop.Target"/>
<!--2、切面對象-->
<bean id="myAspect" class="aop.MyAspect"></bean>
<!--3、配置織入:告訴spring框架,哪些方法需要進(jìn)行哪些增強(qiáng)(前置,后置,等等...)-->
<aop:config>
<!--聲明切面-->
<aop:aspect ref="myAspect">
<!--切面:切點(diǎn)+通知,注意下面的這組</aop:before>標(biāo)簽要在同一行才行,不然會報錯-->
<aop:before method="before" pointcut="execution(public void aop.Target.save())"></aop:before>
<aop:around method="around" pointcut="execution(* aop..*.*(..))"/>
<aop:before method="before" pointcut="execution(* aop.*.*(..))"></aop:before>
<aop:after-returning method="afterReturning" pointcut="execution(* aop.*.*(..))"/>
<aop:after-throwing method="afterThrowing" pointcut="execution(* aop..*.*(..))"></aop:after-throwing>
<aop:after method="after" pointcut="execution(* *..*.*(..))"/>
<!--抽取切點(diǎn)表達(dá)式-->
<aop:pointcut id="myPointcut" expression="execution(* aop.*.*(..))"/>
<aop:around method="around" pointcut-ref="myPointcut"/>
<aop:after method="after" pointcut-ref="myPointcut"/>
</aop:aspect>
</aop:config>
</beans>
(5) xml配置AOP詳解。
(5.1)切點(diǎn)表達(dá)式的寫法。?
(5.2)通知的類型。
(5.3)切點(diǎn)表達(dá)式的抽取。
(5.4)知識要點(diǎn)。
(6)注解配置——AOP的快速入門。
(7)注解配置AOP詳解。
(7.1)注解通知的類型。
(7.2)切點(diǎn)表達(dá)式的抽取。
@Component("myAspect")
@Aspect//標(biāo)注當(dāng)前MyAspect是一個切面類
public class MyAspect {
@Around("pointcut()")
public Object around(ProceedingJoinPoint pjo) throws Throwable {
System.out.println("環(huán)繞前增強(qiáng)......");
Object proceed = pjo.proceed();//切點(diǎn)方法
System.out.println("環(huán)繞后增強(qiáng)......");
return proceed;
}
//@After("execution(* *..*.*(..))")
@After("MyAspect.pointcut()")
public void after(){
System.out.println("最終增強(qiáng)......");
}
//定義一個切點(diǎn)表達(dá)式
@Pointcut("execution(* *..*.*(..))")
public void pointcut(){ }//這個只是借助這個方法寫注解,即便把這個改成字段也行...
}
?@Around("pointcut()") 與@Around("類名.pointcut()")都可以。
文章來源:http://www.zghlxwxcb.cn/news/detail-423757.html
(7.3)?知識要點(diǎn)。?
文章來源地址http://www.zghlxwxcb.cn/news/detail-423757.html
到了這里,關(guān)于26.Spring-AOP(切面編程)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!