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相关推荐

  1. spring声明式事务管理方式( 基于tx和aop名字空间的xml配置+@Transactional注解)

    1. 声明式事务管理分类 声明式事务管理也有两种常用的方式, 一种是基于tx和aop名字空间的xml配置文件,另一种就是基于@Transactional注解. 显然基于注解的方式更简单易用,更清爽. ...

  2. spring boot注解之AOP基于@Aspect的AOP配置

    Spring AOP面向切面编程,可以用来配置事务.做日志.权限验证.在用户请求时做一些处理等等.用@Aspect做一个切面,就可以直接实现. 1.首先定义一个切面类,加上@Component  @A ...

  3. spring cloud 入门系列七:基于Git存储的分布式配置中心--Spring Cloud Config

    我们前面接触到的spring cloud组件都是基于Netflix的组件进行实现的,这次我们来看下spring cloud 团队自己创建的一个全新项目:Spring Cloud Config. 它用来 ...

  4. Spring学习第6篇: 基于注解使用IOC

    大家家好,我是一名网络怪咖,北漂五年.相信大家和我一样,都有一个大厂梦,作为一名资深Java选手,深知Spring重要性,现在普遍都使用SpringBoot来开发,面试的时候SpringBoot原理也 ...

  5. 【Spring AOP】基于注解的 AOP 编程

    Spring AOP 基于注解的 AOP 编程的开发 开发步骤 切入点复用 切换动态代理的创建方式(JDK.Cglib) AOP 开发中的一个坑(业务方法互相调用) AOP 知识总结 更多内容请查看笔 ...

  6. Spring学习总结二

    Spring框架的代理与AOP.AspectJ Spring学习总结二 0.在理解什么是AOP之前的一些话 1.什么是AOP 2.AOP的重要概念 3.代理模式 3.1.静态代理 3.2.动态代理 3 ...

  7. SpringAOP描述及实现_AspectJ详解_基于注解的AOP实现_SpringJdbcTemplate详解

    AOP AOP特点: 面向切面编程, 利用AOP对业务逻辑的各个部分进行抽取公共代码, 降低耦合度, 提高代码重用性, 同时提高开发效率. 采取横向抽取, 取代传统纵向继承体系重复性代码 解决事务管理 ...

  8. 20.Spring学习笔记_基于配置文件的方式来配置 AOP(by尚硅谷_佟刚)

    基于 XML 的配置声明切面 除了使用 AspectJ 注解声明切面, Spring 也支持在 Bean 配置文件中声明切面. 这种声明是通过 aop schema 中的 XML 元素完成的. 正常情 ...

  9. spring学习总结(十):基于 XML 的配置AOP

    基于 XML 的配置声明AOP 除了使用 AspectJ 注解声明切面, Spring 也支持在 Bean 配置文件中声明切面. 这种声明是通过 aop schema 中的 XML 元素完成的. 正常 ...

  10. 面向切面(AOP)之Spring接口方式 schema配置方式 aspectj注解方式

    一.初识AOP   关于AOP的学习可以参看帮助文档:spring-3.2.0.M2\docs\reference\html目录下index.html的相关章节      1.AOP:Aspect-O ...

最新文章

  1. spring 配置文件位置
  2. [angularjs] angularjs系列笔记(四)控制器
  3. CEF(包含均衡负载)
  4. pythonweb开发-手把手教你写网站:Python WEB开发技术实战
  5. 发送文件到打印机,打印机收不到(无线打印机)
  6. Windows环境下学习Lisp和Scheme的两大利器
  7. 电气:蒙特卡洛1000个风光场景并通过削减法|聚类法得到几个典型场景(matlab\python实现)
  8. C++学习笔记-----函数调用时的决议:名字查找,重载决议,可访问性检测
  9. 使用js如何获取treeview控件的当前选中的节点
  10. Lync Server 2010的部署系列_第七章 部署边缘服务器(上)
  11. html文字添加波浪线,利用css渐变给文字下方加波浪线
  12. 超图Cesium二三维切换
  13. XNA实现不停循环的路的效果
  14. 用java语言编写的操作系统属于_为什么操作系统不是用java编写的?
  15. (5)通过输入参数(测量数据)构建二维体模型(01)
  16. 利用反射生成SQL语句
  17. web javescript与cookie理解
  18. Fast Global Registration
  19. 电信物联网平台申请正式平台流程
  20. 原理篇4、CH9328使用

热门文章

  1. php浏览服务器某一文件夹内容,php删除web服务器中指定目录下的指定格式的文件...
  2. 微信第三方扫描登录 java源代码_微信开放平台基于网站应用授权登录源码(java)...
  3. java多态的两种形式_java核心(八):继承与方法重写、final、多态性的两种描述形式...
  4. html5 输入框有值无效,HTML5基础 input required 输入框内必须有内容
  5. 中print中加f_Python3中的格式化输出
  6. 清华大学计算机系高考生源,清华大学在这个高考大省录取人数创新高,网友:仍然是同分不同命...
  7. linux环境对xml的影响,Linux下XPath对xml解析
  8. mysql sqlstate 08001_关于Toad连接DB2的sqlstate=08001错误
  9. Linux16.04和Windows 10双系统下,解决时间不一致问题
  10. 湖北省仙桃市2021年高考成绩查询,2021年4月湖北仙桃市自考成绩查询时间和有效期是多久?...