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>
  • 相关阅读:
    mexopencv
    Computer Vision Resources
    Immersive Imaging
    汇编指令
    I/O输入系统
    大容量存储器的结构
    文件系统实现
    文件系统接口
    虚拟内存
    内存管理
  • 原文地址:https://www.cnblogs.com/jeremy-blog/p/4055137.html
Copyright © 2011-2022 走看看