学习记录 - 配置切面aspect和切入点PointCut

配置切面aspect

	<aop:config>
		<aop:aspect id="moocAspectAOP" ref="moocAspect">

		</aop:aspect>
	</aop:config>


配置pointcut

name-pattern:指定方法名,*代表所以,set*,代表以set开头的所有方法.
parameters pattern:指定方法参数(声明的类型),(..)代表所有参数,(*)代表一个参数,(*,String)代表第一个参数为任何值,第二个为String类型.


Aspectj和Spring AOP都支持的:

1.execution(public **(..)) 切入点为执行public方法时

2.execution(* set*(..))切入点为执行所有set开始的方法时

3.execution(* com.xyz.service.AccountService.*(..))切入点为执行AccountService类中的所有方法时 AccountService 接口的任意方法的执行:

4.execution(* com.xyz.service..(..))切入点为执行com.xyz.service包下的所有方法时

5.execution(* com.xyz.service...(..))切入点为执行com.xyz.service包及其子包下的所有方法时


Spring AOP才支持的:

within(com.xyz.service.*)类中

within(com.xyz.service..*) 包中

within用于匹配指定类型内的方法执行


this(com.xyz.service.AccountService)

this用于匹配当前AOP代理对象类型的执行方法


target(com.xyz.service.AccountService)

target用于匹配当前目标对象类型的执行方法

args(java.io.Serializable)

args用于匹配当前执行的方法传入的参数为指定类型的执行方法


带有@Transactional标注的所有类的任意方法.
@within(org.springframework.transaction.annotation.Transactional)
@target(org.springframework.transaction.annotation.Transactional)


带有@Transactional标注的任意方法.
@annotation(org.springframework.transaction.annotation.Transactional)
***> @within和@target针对类的注解,@annotation是针对方法的注解

参数带有@Transactional标注的方法.
@args(org.springframework.transaction.annotation.Transactional)
参数为String类型(运行是决定)的方法.
args(String)

切入点配置范例

	<aop:config>
		<aop:aspect id="moocAspectAOP" ref="moocAspect">
			<aop:pointcut expression="execution(* com.imooc.aop.schema.advice.biz.*Biz.*(..))" id="moocPiontcut"/>

		</aop:aspect>
	</aop:config>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值