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/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/aop
http://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>

Spring学习(20)--- Schema-based AOP(基于配置的AOP实现) -- 配置切入点pointcut的更多相关文章

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

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

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

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

  3. Spring 学习教程(二): IOC/DI+AOP

    1. IOC / DI Spring是一个基于IOC和AOP的结构J2EE系统的框架 IOC 反转控制 是Spring的基础,Inversion Of Control 简单说就是创建对象由以前的程序员 ...

  4. .NetCore学习笔记:三、基于AspectCore的AOP事务管理

    AOP(面向切面编程),通过预编译方式和运行期间动态代理实现程序功能的统一维护的一种技术.AOP是OOP的延续,是函数式编程的一种衍生范型.利用AOP可以对业务逻辑的各个部分进行隔离,从而使得业务逻辑 ...

  5. spring cloud 入门系列七:基于Git存储的分布式配置中心

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

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

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

  7. 第三章 AOP 基于@AspectJ的AOP

    在前面,我们分别使用Pointcut.Advice.Advisor接口来描述切点.增强.切面.而现在我们使用@AdpectJ注解来描述. 在下面的例子中,我们是使用Spring自动扫描和管理Bean. ...

  8. Java框架spring 学习笔记(十四):注解aop操作

    回见Java框架spring Boot学习笔记(十三):aop实例操作,这里介绍注解aop操作 首先编写一个切入点HelloWorld.java package com.example.spring; ...

  9. Spring 学习笔记 4. 尚硅谷_佟刚_Spring_属性配置细节

    1,字面值 •字面值:可用字符串表示的值,可以通过 <value> 元素标签或 value 属性进行注入. •基本数据类型及其封装类.String 等类型都可以采取字面值注入的方式 •若字 ...

  10. Spring学习手札(二)面向切面编程AOP

    AOP理解 Aspect Oriented Program面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术. 但是,这种说法有些片面,因为在软件工程中,AOP的价值体现的并 ...

随机推荐

  1. 这可能是php世界中最好的日志库——monolog

    由于一些历史原因,php中并没有内建的日志接口,故长期以来也没一个功能完备并且应用广泛的日志库.在我的工作生涯中,如果系统需要记录一些应用日志的话,基本上就是封装一个日志类,然后把一些要记录的字段写入 ...

  2. com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method findUserByUserNo in the service wusc.edu.facade.user.service.PmsUserFacade.

    017-04-25 10:55:30,505 INFO [AbstractRegistry.java:302] : [DUBBO] Register: consumer://192.168.1.101 ...

  3. CSS3弹性伸缩布局(上)——box布局

    布局简介 CSS3提供了一种崭新的布局方式:Flexbox布局,即弹性伸缩布局模型(Flexible Box)用来提供一个更加有效的方式实现响应式布局. 由于这种布局还处于W3C的草案阶段,并且它分为 ...

  4. [周译见] C# 7 中的模范和实践

    原文地址:https://www.infoq.com/articles/Patterns-Practices-CSharp-7 关键点 遵循 .NET Framework 设计指南,时至今日,仍像十年 ...

  5. SpringMVC+Spring 事务无法回滚的问题

    问题描述: Controller里面执行Service的方法,Service方法抛出异常,但是没有按照事务配置的方式回滚: Service的事务配置没有问题: 出现此问题的原因: 在springmvc ...

  6. [转载]PHP检测一个元素是否存在于数组中

  7. NUMBER_GET_NEXT 获取编号 遇到关于按年度编号的问题

    最近给财务做了一个平台,在系统创建一些特殊类型的合同,需要生成合同编号:财务要求 合同类型+公司代码 +年+三位流水号, eg:CP6008-2017001 SNRO 子对象数据元素就是 公司代码 不 ...

  8. Linux下的Jenkins+Tomcat+Maven+Gitlab+Shell环境的搭建使用(jenkins自动化部署)

    jenkins自动化部署 目标:jenkins上点构建(也可以自动检查代码变化自动构建)>>>项目部署完成. 一.安装jenkins 1.下载jenkins 这里我选择的是war包安 ...

  9. java基础---->hashMap的简单分析(一)

    HashMap是一种十分常用的数据结构对象,可以保存键值对.它在项目中用的比较多,今天我们就来学习一下关于它的知识. HashMap的简单使用 一.hashMap的put和get方法 Map<S ...

  10. 【转】Java方向如何准备BAT技术面试答案(汇总版)

    原文地址:http://www.jianshu.com/p/1f1d3193d9e3 这个主题的内容之前分三个篇幅分享过,导致网络上传播的比较分散,所以本篇做了一个汇总,同时对部分内容及答案做了修改, ...