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. 八种创建等高列布局【出自w3c】

    高度相等列在Web页面设计中永远是一个网页设计师的需求.如果所有列都有相同的背景色,高度相等还是不相等都无关紧要,因为你只要在这些列的父元素中设置一个背景色就可以了.但是,如果一个或多个列需要单独设置 ...

  2. 探讨数据进行AES加密和解密以及.NET Core对加密和解密为我们提供了什么?

    前言 对于数据加密和解密每次我都是从网上拷贝一份,无需有太多了解,由于在.net core中对加密和解密目前全部是统一了接口,只是做具体的实现,由于遇到过问题,所以将打算基本了解下其原理,知其然足矣, ...

  3. json、xml和java对象之间的转化

    其实从面相对象的角度来理解这个问题,就会很清晰.java中的一切皆对象即把世间万物(Everything in the world)看做java对象,任何处理不了的问题都可以先转化成java对象在做处 ...

  4. eclipse简介及下载

    一.Eclipse 是非常着名的跨平台的自由集成开发环境(IDE).最初主要用来Java语言开发,但是目前亦有人通过插件使其作为其他计算机语言比如C++和Python的开发工具. 二.Eclipse的 ...

  5. Struts流程分析+源码分析

    1.初始化工作 读取配置---转换器-----读取插件 当struts-config.xml配置文件加载到内存,则会创建两个map:ActionConfigs,FromBeans.这两个map都交由M ...

  6. JSP Cookie的使用

    Cookie 通常用于网站记录客户的某些信息,比如客户的用户名及客户的喜好等.一旦用户下次登录,网站可以获取到客户的相关信息,根据这些客户信息,网站可以对客户提供更友好的服务. Cookie sess ...

  7. 【flex弹性盒布局】------这个强大的功能

    你知道flex弹性布局么? 我们先来了解它的概念:Flex是Flexible Box的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性. 任何一个容器都可以指定为Flex布局 ...

  8. 【2017-05-21】WebForm内置对象:Session、Cookie,登录和状态保持

    1.Request -获取请求对象 string s =Request["key"]; 2.Response  -  响应请求对象 Response.Redirect(" ...

  9. c++ 自动应用类型转换

    c++中,在赋值时如果类型不匹配,就会应用到:类型转换.类型转换又分为隐式转换(implicit conversion) 和 显式强制类型转换(emplcit conversion).在这我围绕着类的 ...

  10. PHP如何与搜索引擎Elasticsearch交互?

    一:参考官方文档 1. Elasticsearch 5.4.0英文手册:https://www.elastic.co/guide/en/elasticsearch/reference/5.4/sear ...