Spring编程<七>

来源:互联网 发布:施工进度网络计划图 编辑:程序博客网 时间:2024/06/06 16:58

Spring编程<七>

AOP第四种方法:

将一个POJO做成切面:需要在配置文件中

 <!-- 切面=切点(切点语言的表达式)+通知 -->     <!-- 利用基本标签的切面技术 把一个POJO做成切面 -->     <bean id="myAdvisor" class="cn.hncu.v4.MyAdvisor"> </bean>     <aop:config>        <aop:aspect ref="myAdvisor">            <aop:pointcut expression="execution( * cn..Cat.*(..) ) " id="cut"/>            <!-- after代表放行后在执行-->            <aop:after method="aa" pointcut-ref="cut"/>        </aop:aspect>     </aop:config>

这里写图片描述

也可以只接在中间写切点语言:

 <bean id="myAdvisor2" class="cn.hncu.v4.MyAdvisor2"> </bean>     <aop:config>        <aop:aspect ref="myAdvisor2">            <aop:before method="bf" pointcut="execution( * cn..Person.*(..) )"/>            <aop:around method="around" pointcut="execution( * cn..Person.run(..))"/>        </aop:aspect>     </aop:config>

这里写图片描述

演示结果:

这里写图片描述

原创粉丝点击