zoukankan      html  css  js  c++  java
  • spring学习笔记(六)

    1.配置环绕通知

      需要实现的接口为  MethodInterceptor

      代码举例

     1 package com.huawei.aop;
     2 
     3 import org.aopalliance.intercept.MethodInterceptor;
     4 import org.aopalliance.intercept.MethodInvocation;
     5 
     6 public class MyMethodInterceptor implements MethodInterceptor 
     7 {
     8 
     9     @Override
    10     public Object invoke(MethodInvocation arg0) throws Throwable
    11     {
    12         System.out.println("执行前...");
    13         Object obj = arg0.proceed();
    14         System.out.println("执行后...");
    15         return obj;    //要返回对象,类似filterChain,返回null,可能导致程序不继续执行
    16     }
    17 
    18 }

     2.异常通知

     需要实现的接口 ThrowAdvice

    3.定义切入点

     需要在配置文件中配置

     1 <!--定义前置通知的切入点-->
     2 <bean id="myMethodBeforeAdviceFilter" class="org.springframework.aop.support.NameMatchMethodPointcutAdvice">
     3     <property name="advice" rel="myBeforeAdvice"/>
     4     <property name="mappedNames">
     5           <list>
     6                <!--这里可以使用正则表达式匹配方法  例如  say*-->
     7               <value>sayHello</value>
     8           </list>
     9      </property>
    10 </bean>
    11 
    12 .....
    13 <!--将通知织入代理对象-->
    14 <property name="interceptorNames">
    15     <list>
    16         <value>myMethodBeforeAdviceFilter</value>
    17         <value>myAfterServiceAdvice</value>
    18         <value>myMethodInterceptor</value>
    19     </list>   
    20 </property>
  • 相关阅读:
    02-css的选择器学习.html
    01-css-css的声明.html
    10-描点学习
    09-HTML-form标签学习.html
    08-HTML-框架标签学习.html
    07-HTML-内嵌标签学习.html
    06-HTML-表格标签学习.html
    05-HTML-超链接标签.html
    04-HTML-图片标签学习.html
    03-HTML-body标签(列表标签).html
  • 原文地址:https://www.cnblogs.com/yiliweichinasoft/p/3581302.html
Copyright © 2011-2022 走看看