首页 技术 正文
技术 2022年11月21日
0 收藏 614 点赞 4,984 浏览 1032 个字

在我的另一篇文章中(http://www.cnblogs.com/anivia/p/5687346.html),通过一个例子介绍了基于注解配置spring增强的方式,那么这篇文章,只是简单的说明,如何通过xml来实现基于注解代码的增强效果,具体做法是:

1、JAVA代码中不再使用注解

2、在资源配置xml文件中,通过xml的方式声明主逻辑Bean和切面Bean,并使用<aop>标签配置切入点和增强,配置的方式为:

    <!-- 切面 -->    <bean id="aopBean"        class="com.minlz.aop.anno.AnnoAspectBean"/>    <!-- 主逻辑 -->    <bean id="annoService"        class="com.minlz.aop.anno.AnnoService"/>    <aop:config>        <aop:aspect ref="aopBean">            <aop:pointcut expression="execution(* com.minlz.aop.anno..*.mainService(..)) and args(param)" id="aopPoint"/>            <aop:before method="before" pointcut-ref="aopPoint"/>            <aop:after method="after" pointcut-ref="aopPoint"/>            <aop:after-throwing method="afterThrowing" pointcut-ref="aopPoint" throwing="ex"/>            <aop:after-returning method="afterReturning" pointcut-ref="aopPoint" returning="retValue"/>            <aop:around method="around" pointcut-ref="aopPoint"/>        </aop:aspect>    </aop:config>

简单解释下XML的配置元素

1、首先声明两个Bean,这个很好理解

2、<aop:config>标签,是配置AOP的主要标签,里面可以配置多个切面(<aop:aspect>),引用一个切面Bean,且通过多种标签配置前置增强,后置增强,异常抛出增强等,都是引用一个切入点,配置返回值参数名或者异常名等。

这样配置之后运行结果,同注解配置相同。

PS:如果错误,请大家赐教,不胜感激!如果疑惑,也可相互交流学习。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,992
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,506
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,767
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844