zoukankan      html  css  js  c++  java
  • AOP

    AOP是面向对象的思维方式的有力补充。好处:可以动态的添加和删除在切面上的逻辑而不影响原来的执行代码

    1.Anotation

    a.在命名空间中加入xsd文件spring-aop.xsd

    b.在配置文件中写入<aop:aspectj-autoproxy />   aspectj是专门用来实现代理的框架,可以使用aspectj注解的方式定义spring的AOP

    c.此时就可以解析对应的Annotation了

    d.建立自己的拦截类,用@aspect注解这个类

    e.建立处理方法,用@Before来注解这个方法,写明白切入点(execution...)

    f.让spring对自己的拦截器类进行管理@component

    想要在编写配置文件的时候又提示,window--proferences--xmlcatalog--add

    import org.aspectj.lang.annotation.Aspect;

    import org.aspectj.lang.annotation.Before;

    import org.springframework.stereotype.Component;

    @Aspect

    @Component//将切面类本身初始化

    public class LogInterceptor{

      @Before("execution(public void  ........)//切入点语法

      public void beforeMethod(){

        System.out.println("method start");

      }

    }

    aspect:切面类及其中的切面逻辑

    要为没有实现接口的类动态的产生代理需要引入cglib包

    2.XML

    初始化切面类<bean id="logInterceptor" class="com......"></bean>

              <aop:config>

                  <aop:pointcut expression="execution(....)" id="servicePointcut" />// 全局的pointcut,即在哪些方法上加切面逻辑

                  <aop:aspect id="logAspect" ref="切面类">//声明切面对象

                    <aop:before method="before" pointcut-ref="servicePointcut" />//也可以不用pointcut-ref,而直接定义pointcut,直接指定pointcut

                  </aop:aspect>

              </aop:cofig>

  • 相关阅读:
    hdu 3613 Best Reward 扩展kmp
    hdu 4333 Revolving Digits 扩展kmp
    poj 1904 King's Quest 强连通
    hdu 3068 最长回文 manacher
    Codeforces Round #243 (Div. 2) C. Sereja and Swaps
    poj 3680 Intervals 费用流
    两个kmp hdu 2594 & hdu 2087
    hdu 3336 count the string
    Arcgis安装要素
    JS关闭窗口而不提示
  • 原文地址:https://www.cnblogs.com/Earl/p/1749049.html
Copyright © 2011-2022 走看看