zoukankan      html  css  js  c++  java
  • spring学习--4

    参考书籍《spring in action》
     
    1. AOP
    before you wak the walk, you have to learn to walk the walk.
    1) advice---the job of an aspect (what and when)
    /before
    /after
    /after-returning
    /after throwing
    /around: beforen and after
    2) join points---a point in the execution of the application where an aspect can be plugged in.
    3)pointcuts---where the advice should be woven
    4)aspects--- advice & joincuts
    5)introduction---add new methods or attributes to existing classes.
    6)weaving---the process of applyng aspects to target object to create a
     new proxied object.
    /compile time
    /class load time
    /runtime
    2. spring 对AOP的支持方式
    1)classic spring proxy-based AOP
    2)pure-POJO aspects
    3) @AspectJ annotation driven aspects.
    4) injected AspectJ aspects.
     
    3.creating aspect in spring
    1)selecting join points with pointcuts.
    eg:
    execution(* concert.Performance.perform())
    and bean('woodstock')
    2) creating annotated aspects
    @Aspect
    public class Audience {
    @Pointcut("execution(** concert.Performance.perform(..))")
    public void performance() {}
    @Before("performance()")
    public void silenceCellPhones() {
    System.out.println("Silencing cell phones");
    }
    @Before("performance()")
    public void takeSeats() {
    System.out.println("Taking seats");
    }
    @AfterReturning("performance()")
    public void applause() {
    System.out.println("CLAP CLAP CLAP!!!");
    }
    @AfterThrowing("performance()")
    public void demandRefund() {
    System.out.println("Demanding a refund");
    }
    }

    配置:

    @Configuration
    @EnableAspectJAutoProxy
    @ComponentScan
    public class ConcertConfig {
    @Bean
    public Audience audience() {
    return new Audience();
    }
    }

    3)handling params in advice

    4) annotation introductions

    dynamic language like ruby and groovy can add new methods to an object or class.

     
     
  • 相关阅读:
    BC高精确度函数使用。
    thinkPHP中_initialize方法实例分析
    MySQL中concat函数
    使用docker打造spark集群
    zhihu spark集群,书籍,论文
    Windows下安装使用curl命令
    数据可视化的优秀入门书籍有哪些,D3.js 学习资源汇总
    2015互联网+影响力报告发布
    The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
    centos linux中怎么查看和修改计算机名/etc/sysconfig/network
  • 原文地址:https://www.cnblogs.com/flyingbee6/p/5351676.html
Copyright © 2011-2022 走看看