spring-aop-@Aspect说明

@AspectJ的详细用法 
spring AOP中目前只有执行方法这一个连接点,Spring AOP支持的AspectJ切入点指示符如下:

一些常见的切入点的例子 
execution(public * * (. .)) 任意公共方法被执行时,执行切入点函数。 
execution( * set* (. .)) 任何以一个“set”开始的方法被执行时,执行切入点函数。 
execution( * com.demo.service.AccountService.* (. .)) 当接口AccountService 中的任意方法被执行时,执行切入点函数。 
execution( * com.demo.service.. (. .)) 当service 包中的任意方法被执行时,执行切入点函数。 within(com.demo.service.) 在service 包里的任意连接点。 within(com.demo.service. .) 在service 包或子包的任意连接点。 
this(com.demo.service.AccountService) 实现了AccountService 接口的代理对象的任意连接点。 
target(com.demo.service.AccountService) 实现了AccountService 接口的目标对象的任意连接点。 
args(Java.io.Serializable) 任何一个只接受一个参数,且在运行时传入参数实现了 Serializable 接口的连接点 
增强的方式: 
@Before:方法前执行 
@AfterReturning:运行方法后执行 
@AfterThrowing:Throw后执行 
@After:无论方法以何种方式结束,都会执行(类似于finally) 
@Around:环绕执行

猜你喜欢

转载自memoryforwyl.iteye.com/blog/2329558
今日推荐