spring aop 配置使用说明
2015-11-26 15:58
399 查看
<aop:config>标签
<bean id="profiler" class="SimpleProfiler"/> //这是你要进行对切面拦截处理的另一个定义的类
<aop:config>
<aop:aspect ref="profiler">
<aop:pointcut id="aopafterMethod" expression="execution(* FooService.*(..))"/>
//定义的切面 即你要进行拦截的类
<aop:after pointcut-ref="aopafterMethod" method="afterMethod"/>//拦截类执行后再去执行你定义的类
红色是你定义类的方法名
<aop:pointcut id="aopBefore" expression="execution(* FooService.getBefore(String)) and args(myName)"/>
切面
<aop:before pointcut-ref="aopBefore" method="beforeMethod"/>
执行拦截前 执行你定义的类
</aop:aspect>
</aop:config>
另注
expression="execution(
表达式说明
任意公共方法的执行:
execution(public * *(..))
任何一个以“set”开始的方法的执行:
execution(* set*(..))
AccountService 接口的任意方法的执行:
execution(* com.xyz.service.AccountService.*(..))
定义在service包里的任意方法的执行:
execution(* com.xyz.service.*.*(..))
定义在service包和所有子包里的任意类的任意方法的执行:
execution(* com.xyz.service..*.*(..))
定义在pointcutexp包和所有子包里的JoinPointObjP2类的任意方法的执行:
execution(* com.test.spring.aop.pointcutexp..JoinPointObjP2.*(..))")
***> 最靠近(..)的为方法名,靠近.*(..))的为类名或者接口名,如上例的JoinPointObjP2.*(..))
<bean id="profiler" class="SimpleProfiler"/> //这是你要进行对切面拦截处理的另一个定义的类
<aop:config>
<aop:aspect ref="profiler">
<aop:pointcut id="aopafterMethod" expression="execution(* FooService.*(..))"/>
//定义的切面 即你要进行拦截的类
<aop:after pointcut-ref="aopafterMethod" method="afterMethod"/>//拦截类执行后再去执行你定义的类
红色是你定义类的方法名
<aop:pointcut id="aopBefore" expression="execution(* FooService.getBefore(String)) and args(myName)"/>
切面
<aop:before pointcut-ref="aopBefore" method="beforeMethod"/>
执行拦截前 执行你定义的类
</aop:aspect>
</aop:config>
另注
expression="execution(
表达式说明
任意公共方法的执行:
execution(public * *(..))
任何一个以“set”开始的方法的执行:
execution(* set*(..))
AccountService 接口的任意方法的执行:
execution(* com.xyz.service.AccountService.*(..))
定义在service包里的任意方法的执行:
execution(* com.xyz.service.*.*(..))
定义在service包和所有子包里的任意类的任意方法的执行:
execution(* com.xyz.service..*.*(..))
定义在pointcutexp包和所有子包里的JoinPointObjP2类的任意方法的执行:
execution(* com.test.spring.aop.pointcutexp..JoinPointObjP2.*(..))")
***> 最靠近(..)的为方法名,靠近.*(..))的为类名或者接口名,如上例的JoinPointObjP2.*(..))
相关文章推荐
- Exception in thread "main" java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z
- 菜鸟学Java----Java面向对象
- struts2 原理
- SpringMVC4 配置
- java开发记录
- Java的Struts框架中<results>标签的使用方法
- eclipse出现乱码的情况
- 大数java来一波
- java如何连接MySQL数据库?
- Java的Struts框架中Action的编写与拦截器的使用方法
- 一图搞定【实战Java高并发程序设计】
- Eclipse快捷键大全(转载)
- Java系列:《Java核心技术 卷一》学习笔记,chapter11 记录日志
- Java static关键字
- spring security - 自定义登陆
- java计算相隔时间差以及Joda-Time
- 一图搞定【实战Java高并发程序设计】
- 【Struts2】(1)第一个程序
- java Socket用法详解
- JAVA基础之OO简介