• Spring 学习——Spring AOP——AOP配置篇Aspect、Pointcut


    Schena——based AOP

    • 声明
      • Spring所有的切面和通知器都必须放在一个<aop:config>标签内,可以同时配置多个<aop:config>元素。
      • 每一个<aop:config>内可以包含pointcut、advisor、aspect元素,但是必须按照这3个元素指定顺序进行声明。

    声明切面Aspect

    <?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:context="http://www.springframework.org/schema/context"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop.xsd" >
    
            <bean id="ikAspect" class="com.jing.spring.aop.IKAspect"></bean>
            <bean id="ikAspectBiz" class="com.jing.spring.aop.IKAspectBiz"></bean>
    
            <aop:config>
                    <aop:aspect id="ikAspectAop" ref="ikAspect"></aop:aspect>
            </aop:config>
    </beans>
    • Next

    声明通知Pointcut

    • 使用形式
      • com.jing.spring.service.AccountService.setAbnormal()。切入点为具体某一个方法。:Aspect和Spring Aop 都支持
      • execution(public * *(..)) :切入点为执行所有public方法。:Aspect和Spring Aop 都支持
      • execution(* set*(..)):切入点为执行所有set方法。:Aspect和Spring Aop 都支持
      • execution(* com.jing.spring.service.AccountService.*(..)):切入点为执行AccountService类中所有方法时。:Aspect和Spring Aop 都支持
      • execution(* com.jing.spring.service..(..)):切入点为执行com.jing.spring.service包下所有方法时。:Aspect和Spring Aop 都支持
      • execution(* com.jing.spring.service...(..)):切入点为执行com.jing.spring.service包及其子包下的所有方法时。:Aspect和Spring Aop 都支持
      • within:用于匹配指定类型内的方法。:only used by Spring AOP
        • with(com.jing.spring.service.*)
        • with(com.jing.spring.service..*)
      • target:匹配当前目标对象类型的执行方法。:only used by Spring AOP
      • args:匹配参数。:only used by 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:context="http://www.springframework.org/schema/context"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop.xsd" >
    
            <bean id="ikAspect" class="com.jing.spring.aop.IKAspect"></bean>
            <bean id="ikAspectBiz" class="com.jing.spring.aop.IKAspectBiz"></bean>
    
            <aop:config>
                    <aop:aspect id="ikAspectAop" ref="ikAspect">
                            <aop:pointcut id="ikPoint" expression="execution(* com.jing.spring.aop.IKAspectBiz.*(..))"></aop:pointcut>
                    </aop:aspect>
            </aop:config>
    </beans>
    • Next
  • 相关阅读:
    《英语语法新思维初级教程》学习笔记(七)五种基本句型
    《英语语法新思维初级教程》学习笔记(六)实义动词与(情态)助动词
    《英语语法新思维初级教程》学习笔记(五)形容词
    《英语语法新思维初级教程》学习笔记(四)数量限定词和个体限定词
    C# Redis存Session Hash存对象
    MVC中Spring.net 对基类控制器无效 过滤器控制器无效
    C# datagridview列绑定类中类的属性
    商品评分效果JavaScript
    C# SQL数据库学习时遇到到一些异常
    C语言用一维数组打印杨辉三角(原:无意中想到)
  • 原文地址:https://www.cnblogs.com/zuiyue_jing/p/10429972.html
Copyright © 2020-2023  润新知