當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring学习(20)--- Schema-based AOP(基于配置的AOP实现) -- 配置切入点pointcut
生活随笔
收集整理的這篇文章主要介紹了
Spring学习(20)--- Schema-based AOP(基于配置的AOP实现) -- 配置切入点pointcut
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
pointcut(切斷點)表達式:
- 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用于匹配方法執行的連接點
舉幾個例子:
- execution(public * *(..))?????? 切入點為執行所有public方法時?
- execution(* set*(..))?????? ?切入點為執行所有set開始的方法時
- execution(* com.xyz.service.AccountService.*(..))??????? 切入點為執行AccountService類中所有方法時
- execution(* com.xyz.service..(..))????????????切入點為執行com.xyz.service包下的所有方法時
- execution(* com.xyz.service...(..))??????????? 切入點為執行com.xyz.service包及其子包下的所有方法時
- within(com.xyz.service.*) (only in Spring AOP)
- within(com.xyz.service..*) (only in Spring AOP)??????????? within 用于匹配制定類型內的執行方法
- this(com.xyz.service.AccountService) (only in Spring AOP)????? this 用于匹配當前AOP代理對象類型的執行方法
?其他
- target(com.xyz.service.AccountService)? (only in Spring AOP)??? target 用于匹配當前目標對象類型的執行方法
- args(java.io.Serializable)?? (only in Spring AOP)??????? args 用于匹配當前執行的方法傳入的參數為指定類型的執行方法
基于注解的匹配
- @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)
實現:
<aop:config><aop:pointcut id="businessService" expression="execution(* com.aop.schema..(..))"></aop:pointcut> </aop:config>例子:
新建兩個類
package com.aop.schema; /*** * 切面類**/ public class MyAspect {}?
package com.aop.schema;/*** * 業務類**/ 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>?
轉載于:https://www.cnblogs.com/JsonShare/p/4633564.html
總結
以上是生活随笔為你收集整理的Spring学习(20)--- Schema-based AOP(基于配置的AOP实现) -- 配置切入点pointcut的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Crazy Drops 3
- 下一篇: 转:VMware安装Mac OS X M