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>

  • 相关阅读:
    安卓 日常问题 工作日志20
    安卓 日常问题 工作日志19
    安卓 日常问题 工作日志18
    安卓 日常问题 工作日志17
    安卓 日常问题 工作日志16
    对json进行排序处理
    Eclipse错误: 找不到或无法加载主类或项目无法编译10种解决大法!----------------------转载
    hibernate hql语句 投影查询的三种方式
    新的开始2018/6/8
    SSM搭建
  • 原文地址:https://www.cnblogs.com/Earl/p/1749049.html
Copyright © 2011-2022 走看看