zoukankan      html  css  js  c++  java
  • 基于xml文件的格式配置Spring的AOP

    用例子直接说明:

    <?xml version="1.0" encoding="UTF-8"?>
    <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"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
    <bean id="arithmeticCalculator" class="com.jeremy.aop.xml.ArithmeticCalculatorImpl"></bean>
    
    <!-- 第一步配置Bean,因为切面也是一个Bean -->
    <bean id="loggingAspect" class="com.jeremy.aop.xml.LoggingAspect"></bean>
    
    <!-- 第二部配置AOP -->
    <aop:config>
            <!-- 第三步配置切面使用的表达式 -->
            <aop:pointcut expression="execution(* com.jeremy.aop.xml.ArithmeticCalculator.*(..))" id="pointcut"/>
            <!-- 第四步配置切面,指定切面类 -->
            <aop:aspect ref="loggingAspect">
                <!-- 第五步配置通知 -->
                <aop:before method="beforeMethod" pointcut-ref="pointcut"/>
                <aop:after method="afterMethod" pointcut-ref="pointcut"/>
                <!-- returning:代表返回的值,记得要和通知的方法哪个参数保持一致,其实跟注解一样的,注解的本质就是基于xml配置的 -->
                <aop:after-returning method="AfterReturning" pointcut-ref="pointcut" returning="result"/>
                <!-- e:代表着要传递的异常 -->
                <aop:after-throwing method="AfterThrowing" pointcut-ref="pointcut" throwing="e"/>
                
            </aop:aspect>
    </aop:config>
    
    <bean id="validateAspect" class="com.jeremy.aop.xml.validateAspect"></bean>
    
    </beans>
  • 相关阅读:
    Sikuli:创新的图形化编程技术
    缺少对象 WScript 问题解决方法
    TD8.0迁移到QC9.2,自动迁移失败,手动迁移
    QTP使用小技巧
    外部VBS的调用
    mysql 发生系统错误1067的解决方法
    Mysql 本地计算机无法启动 mysql 服务 错误 1067:进程意外终
    windows下mysql忘记root密码的解决方法
    mysql 常用命令用法总结积木学院整理版
    java、c/c++ 、python 等性能比较 杂谈(整理)
  • 原文地址:https://www.cnblogs.com/jeremy-blog/p/4055137.html
Copyright © 2011-2022 走看看