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/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的更多相关文章
- spring声明式事务管理方式( 基于tx和aop名字空间的xml配置+@Transactional注解)
1. 声明式事务管理分类 声明式事务管理也有两种常用的方式, 一种是基于tx和aop名字空间的xml配置文件,另一种就是基于@Transactional注解. 显然基于注解的方式更简单易用,更清爽. ...
- spring 注解 之 AOP基于@Aspect的AOP配置
Spring AOP面向切面编程,可以用来配置事务.做日志.权限验证.在用户请求时做一些处理等等.用@Aspect做一个切面,就可以直接实现. 1.首先定义一个切面类,加上@Component @A ...
- Spring 学习教程(二): IOC/DI+AOP
1. IOC / DI Spring是一个基于IOC和AOP的结构J2EE系统的框架 IOC 反转控制 是Spring的基础,Inversion Of Control 简单说就是创建对象由以前的程序员 ...
- .NetCore学习笔记:三、基于AspectCore的AOP事务管理
AOP(面向切面编程),通过预编译方式和运行期间动态代理实现程序功能的统一维护的一种技术.AOP是OOP的延续,是函数式编程的一种衍生范型.利用AOP可以对业务逻辑的各个部分进行隔离,从而使得业务逻辑 ...
- spring cloud 入门系列七:基于Git存储的分布式配置中心
我们前面接触到的spring cloud组件都是基于Netflix的组件进行实现的,这次我们来看下spring cloud 团队自己创建的一个全新项目:Spring Cloud Config.它用来为 ...
- spring cloud 入门系列七:基于Git存储的分布式配置中心--Spring Cloud Config
我们前面接触到的spring cloud组件都是基于Netflix的组件进行实现的,这次我们来看下spring cloud 团队自己创建的一个全新项目:Spring Cloud Config.它用来为 ...
- 第三章 AOP 基于@AspectJ的AOP
在前面,我们分别使用Pointcut.Advice.Advisor接口来描述切点.增强.切面.而现在我们使用@AdpectJ注解来描述. 在下面的例子中,我们是使用Spring自动扫描和管理Bean. ...
- Java框架spring 学习笔记(十四):注解aop操作
回见Java框架spring Boot学习笔记(十三):aop实例操作,这里介绍注解aop操作 首先编写一个切入点HelloWorld.java package com.example.spring; ...
- Spring 学习笔记 4. 尚硅谷_佟刚_Spring_属性配置细节
1,字面值 •字面值:可用字符串表示的值,可以通过 <value> 元素标签或 value 属性进行注入. •基本数据类型及其封装类.String 等类型都可以采取字面值注入的方式 •若字 ...
- Spring学习手札(二)面向切面编程AOP
AOP理解 Aspect Oriented Program面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术. 但是,这种说法有些片面,因为在软件工程中,AOP的价值体现的并 ...
随机推荐
- .net之DateTime
Console.WriteLine(DateTime.Now.Year); Console.WriteLine(DateTime.Now.Month); Console.WriteLine(DateT ...
- WF4.0以上使用代码完整自定义动态生成执行工作流Xaml文件
给大家分享一下,如何完全使用代码自定义的创建生成工作流文件(用代码创建Xaml文件),并且动态加载运行所生成的工作流. 工作流生成后 在Xaml文件里的主要节点如下: 输入输出参数 <x:Mem ...
- 从零开始构建一个的asp.net Core 项目
最近突发奇想,想从零开始构建一个Core的MVC项目,于是开始了构建过程. 首先我们添加一个空的CORE下的MVC项目,创建完成之后我们运行一下(Ctrl +F5).我们会在页面上看到"He ...
- tpcc-mysql安装
1.因为我的虚拟机是centos 7 min版本,所以先得安装gcc gcc++: http://mirror.centos.org/centos/7/os/x86_64/Packages/ rp ...
- 用Python设计一个经典小游戏
这是关于Python的第9篇文章,介绍如何用Python设计一个经典小游戏:猜大小. 在这个游戏中,将用到前面我介绍过的所有内容:变量的使用.参数传递.函数设计.条件控制和循环等,做个整体的总结和复习 ...
- 工具类总结---(五)---SD卡文件管理
里面注释很清楚了... package cgjr.com.cgjr.utils; import android.content.Context; import android.graphics.Bit ...
- chkconfig命令(管理开机自启)
提供了一个简单的命令行工具来维护/etc/rc[0-6].d目录层次结构通过减轻系统管理员的直接操作任务,在这些目录中的许多符号链接.仅是简单的改变了符号链接,而非立即启动或禁止一个服务. 语法: c ...
- 异步工作流控制-condCall
在JavaScript编程中,异步操作一直是一个问题,回调是一种深层次的嵌套处理方式,我们也可以把嵌套处理转为直线处理以简化异步处理.有过prolog和erlang编程了解的同学可能对模式匹配有深刻的 ...
- JS判断PC和移动端设备
1.方法一 function IsPC() { var userAgentInfo = navigator.userAgent; var Agents = ["Android", ...
- [linux 整理] linux启动过程3
本文介绍linux启动过程的第三步 busybox--------------------> rc init busybox位置即内容 busybox/init/init.c 1.各种设置信号 ...