當(dāng)前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring学习(20)--- Schema-based AOP(基于配置的AOP实现) -- 配置切入点pointcut
生活随笔
收集整理的這篇文章主要介紹了
Spring学习(20)--- Schema-based AOP(基于配置的AOP实现) -- 配置切入点pointcut
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?
pointcut(切斷點(diǎn))表達(dá)式:
- execution(public * *(..))??
- execution(* set*(..))??
- execution(* com.xyz.service.AccountService.*(..))??
- execution(* com.xyz.service..(..))??
- execution(* com.xyz.service...(..))??
- within(com.xyz.service.*) (only in Spring AOP)
- within(com.xyz.service..*) (only in Spring AOP)
- this(com.xyz.service.AccountService) (only in Spring AOP)
- ....
???? execution用于匹配方法執(zhí)行的連接點(diǎn)
舉幾個(gè)例子:
- execution(public * *(..))?????? 切入點(diǎn)為執(zhí)行所有public方法時(shí)?
- execution(* set*(..))?????? ?切入點(diǎn)為執(zhí)行所有set開始的方法時(shí)
- execution(* com.xyz.service.AccountService.*(..))??????? 切入點(diǎn)為執(zhí)行AccountService類中所有方法時(shí)
- execution(* com.xyz.service..(..))????????????切入點(diǎn)為執(zhí)行com.xyz.service包下的所有方法時(shí)
- execution(* com.xyz.service...(..))??????????? 切入點(diǎn)為執(zhí)行com.xyz.service包及其子包下的所有方法時(shí)
- within(com.xyz.service.*) (only in Spring AOP)
- within(com.xyz.service..*) (only in Spring AOP)??????????? within 用于匹配制定類型內(nèi)的執(zhí)行方法
- this(com.xyz.service.AccountService) (only in Spring AOP)????? this 用于匹配當(dāng)前AOP代理對(duì)象類型的執(zhí)行方法
?其他
- target(com.xyz.service.AccountService)? (only in Spring AOP)??? target 用于匹配當(dāng)前目標(biāo)對(duì)象類型的執(zhí)行方法
- args(java.io.Serializable)?? (only in Spring AOP)??????? args 用于匹配當(dāng)前執(zhí)行的方法傳入的參數(shù)為指定類型的執(zhí)行方法
基于注解的匹配
- @target(org.springframework.transaction.annotation.Transactional)? (only in Spring AOP)
- @within(org.springframework.transaction.annotation.Transactional)? (only in Spring AOP)
- @annotation(org.springframework.transaction.annotation.Transactional)? (only in Spring AOP)
- @args(com.xyz.security.Classified) ? (only in Spring AOP)
實(shí)現(xiàn):
<aop:config><aop:pointcut id="businessService" expression="execution(* com.aop.schema..(..))"></aop:pointcut> </aop:config>例子:
新建兩個(gè)類
package com.aop.schema; /*** * 切面類**/ public class MyAspect {}?
package com.aop.schema;/*** * 業(yè)務(wù)類**/ public class ApsectBiz {}?
XML配置:
<?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"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-4.1.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.1.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-4.1.xsd"><bean id="myAspect" class="com.aop.schema.MyAspect"></bean><bean id="apsectBiz" class="com.aop.schema.ApsectBiz"></bean><aop:config><aop:aspect id="myAspectAOP" ref="myAspect"><aop:pointcut id="myPointcut" expression="execution(* com.aop.schema.ApsectBiz.*(..))" /></aop:aspect></aop:config></beans>?
轉(zhuǎn)載于:https://www.cnblogs.com/JsonShare/p/4633564.html
總結(jié)
以上是生活随笔為你收集整理的Spring学习(20)--- Schema-based AOP(基于配置的AOP实现) -- 配置切入点pointcut的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Crazy Drops 3
- 下一篇: JavaScript匿名函数与托付