欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
Spring Framework中的AOP編程之入門(mén)篇 3

Spring Framework中的AOP編程之入門(mén)篇

2005-12-26 15:30 作者: Russell Miles 出處: bea 責任編輯:方舟
  方面的重用

  可以對方法跟蹤方面進(jìn)行擴展,提供一個(gè)稍微復雜的記錄(Logging)方面。記錄方面提供了一個(gè)很不錯的重用例子,因為記錄方面所需的許多特性都已經(jīng)包含在方法跟蹤方面中了。

  在本例中,記錄方面擴展了方法跟蹤方面,以便顯示附加的與(在應用程序的執行過(guò)程中)所引發(fā)的異常有關(guān)的信息。

  要完全使用記錄方面,需要對應用程序做一些更改。BusinessLogicException異常類(lèi)提供了一個(gè)可以由IBusinessLogicInterface接口和BusinessLogic實(shí)現類(lèi)新增的void bar()方法引發(fā)的異常。

public class BusinessLogicException
extends Exception
{}

public interface IBusinessLogic
{
 public void foo();

 public void bar()
 throws BusinessLogicException;
}

public class BusinessLogic
implements IBusinessLogic
{
 public void foo()
 {
  System.out.println("Inside BusinessLogic.foo()");
 }

 public void bar()
 throws BusinessLogicException
 {
  System.out.println("Inside BusinessLogic.bar()");
  throw new BusinessLogicException();
 }
}

  MainApplication類(lèi)現在將對void bar()方法進(jìn)行一次額外的調用,并處理選中的、可能由該方法引發(fā)的異常。

import org.springframeworkcontext.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class MainApplication
{
 public static void main(String [] args)
 {
  // Read the configuration file
  ApplicationContext ctx = new FileSystemXmlApplicationContext( "springconfig.xml");

  //Instantiate an object
  IBusinessLogic testObject = (IBusinessLogic) ctx.getBean("businesslogicbean");

  //Execute the public methods of the bean
  testObject.foo();

  try
  {
   testObject.bar();
  }
  catch(BusinessLogicException ble)
  {
   System.out.println("Caught BusinessLogicException");
  }
 }
}

  來(lái)自方法跟蹤方面的TracingBeforeAdvice和TracingAfterAdvice通知可以整體重用。LoggingThrowsAdvice類(lèi)為新的異常記錄提供了通知。

import org.springframework.aop.ThrowsAdvice;
import java.lang.reflect.Method;

public class LoggingThrowsAdvice
implements ThrowsAdvice
{
 public void afterThrowing(Method method, Object[] args, Object target, Throwable subclass)
 {
  System.out.println("Logging that a " + subclass + "Exception was thrown.");
 } 
}


  應用記錄方面的最后一步是修改springconfig.xml配置文件,使其包含新添加的LoggingThrowsAdvice通知。

  

圖3顯示了運行MainApplication并使用Spring框架應用了記錄方面的UML順序圖。
  
  圖3. 記錄方面應用到BusinessLogic bean之后的順序圖(單擊圖像查看大圖)   此處的記錄方面清楚地說(shuō)明了如何重用現有方面以及如何在Spring框架中使用通知的throws形式。通過(guò)為before和after通知聲明新的通知來(lái)重寫(xiě)現有的方法跟蹤方面實(shí)現,可以實(shí)現更復雜的記錄方面,記錄到更復雜的記錄框架,比如LOG4J。關(guān)于記錄方面和例子應用程序的源代碼,請參見(jiàn)本文末尾的參考資料小節。

  結束語(yǔ)

  本文展示了使用Spring框架中的基本AOP結構所應用的一些簡(jiǎn)單方面。在本系列的下一篇文章中,我們將介紹一些更實(shí)用的方面,探討方面的生命周期,使用Spring框架的around通知,并使用Spring來(lái)應用AOP模式。
共3頁(yè)。 9 7 1 2 3
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Spring Framework中的面向方面編程(AOP)
Spring Framework中的面向方面編程(AOP),第二部分
一個(gè)簡(jiǎn)單的Spring的AOP例子 - dragon - BlogJava
spring入門(mén)經(jīng)典三
Spring AOP 詳解
Spring AOP 簡(jiǎn)單入門(mén)示例
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久