springframework(十二)AOP之aop标签的支持
来源:互联网 发布:电脑如何复制淘宝链接 编辑:程序博客网 时间:2024/05/21 18:34
spring2.0提供了基于XML Schema的设置和基于Annotation的支持,这两种方式对于AOP在使用上的简化都大有帮助,这里我们只是介绍基于xml的设置。
1、定义一个Advice类,这个advice类不同于以往的,需要集成一些什么advice类。直接就是一个单独的advice类文件。
例如:
其中这个JoinPoint可以省略掉
2)、在配置文件上引入新的xmlns
<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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
3、配置使用,配置文件中声明advice bean。同时使用aop标签来设定适用范围
如上的pointcut中方法名称:
com.itcast.aop.IHello.*(..)表示Ihello方法所声明的任何方法都符合,参数类型设置“(..)”表示任何参数类型声明都符合
Method方法:指明了Advice上要调用的方法名称,这里是TestAdvice中的fff方法
Aop:before表示Advice将作为BeforeAdvice
4、测试类
5、输出结果
透过控制台输出的结果可以看到,任何实现了IHello接口类中的方法调用都调用,都被我们声明的advice给拦截了。
相关的hello接口以及实现类,以及声明,参照如下:
总结:spring的aop标签支持需要在xmlschemal上声明命名空间。并需要编写一个特定格式的advice类,最终使用aop标签完成advice对类的拦截。当我们调用bean的时候,如果符合了aop标签声明的监控范围,他将拦截我们的类。
note:不知道aop标签的写法,看一下spring的reference
- springframework(十二)AOP之aop标签的支持
- springframework(十二)AOP之aop标签的支持
- springframework(六)AOP之静态代理
- springframework(十)AOP之Pointcut、Advisor
- springframework(十一)AOP之自动代理
- springframework(六)AOP之静态代理
- springframework(十)AOP之Pointcut、Advisor
- springframework(十一)AOP之自动代理
- 做一个合格的程序猿之浅析Spring AOP源码(十二) AOP概念理解
- Spring Aop(十二)——编程式的创建Aop代理之AspectjProxyFactory
- springframework(九)AOP的advices,中规中矩的使用方式
- springframework(九)AOP的advices,中规中矩的使用方式
- 【Spring】AOP编程(十二)
- spring对AOP的支持(JDK的动态代理实现AOP和CGLIB实现AOP)
- Spring中的AOP(一)——AOP基本概念和Spring对AOP的支持
- Spring中的AOP(一)——AOP基本概念和Spring对AOP的支持
- Inside-springframework-AOP-creator
- Inside-springframework-AOP-invoke
- 水晶报表入门
- springframework(十一)AOP之自动代理
- 卸载挂载点失败时获取字符串的问题
- 高维数组的名字意义上更接近1阶指针。
- 读完tpop
- springframework(十二)AOP之aop标签的支持
- 职场经验
- C#
- 算法----排序
- EB开发乱码处理总结
- Oracle的面试问题
- Linux目录结构
- 递归输出给定目录下的所有目录和文件
- 搜索引擎与社会责任