<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    J2EE之巔

     

    Spring2 AOP在使用XML配置時如何獲得target及JoinPoint

    蔡超

    SCEA MCSD IBM RUP Specialist

    Spring Reference 中介紹如何在采用 @AspectJ 方式在剖面中如何獲取 target JoinPoint 并給出了示例,但并沒有給出采用 XML 配置方式時介紹及示例,下面附上一個簡單的小例子供大家參考。

    package aop;

    ?

    import org.aspectj.lang.JoinPoint;

    import org.aspectj.lang.ProceedingJoinPoint;

    ?

    /**

    ?* @author Administrator

    ?*

    ?* TODO To change the template for this generated type comment go to

    ?* Window - Preferences - Java - Code Style - Code Templates

    ?*/

    public class LogAdvice1 {

    ?????? public void log(JoinPoint jp,MathImp imp){

    ?

    ????????????? System.out.println("log:"+imp+" "+jp.toLongString());

    ?????????????

    ?????? }

    }

    ?

    /*

    ?* Created on 2006-11-1

    ?*

    ?* TODO To change the template for this generated file go to

    ?* Window - Preferences - Java - Code Style - Code Templates

    ?*/

    package aop;

    ?

    /**

    ?* @author Administrator

    ?*

    ?* TODO To change the template for this generated type comment go to

    ?* Window - Preferences - Java - Code Style - Code Templates

    ?*/

    public class MathImp /*implements Math*/{

    ?

    ?????? /* (non-Javadoc)

    ?????? ?* @see aop.Math#add(int, int)

    ?????? ? */

    ?????? public void add(int op1, int op2) {

    ????????????? // TODO Auto-generated method stub

    ?????????????

    ?????? }

    ?

    ?????? /* (non-Javadoc)

    ?????? ?* @see aop.Math#addtest(int, int)

    ?????? ?*/

    ?????? public void addtest(int op1, int op2) {

    ????????????? // TODO Auto-generated method stub

    ?????????????

    ?????? }

    ?

    ?????? /* (non-Javadoc)

    ?????? ?* @see aop.Math#sub(int, int)

    ?????? ? */

    ?????? public void sub(int op1, int op2) {

    ????????????? // TODO Auto-generated method stub

    ?????????????

    ?????? }

    ?

    }

    ?

    配置:

    <beans xmlns="http://www.springframework.org/schema/beans"

    ????? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    ????? xmlns:aop="http://www.springframework.org/schema/aop"

    ????? xsi:schemaLocation="

    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd

    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

    ?

    ?? <!-- this is the object that will be proxied by Spring's AOP infrastructure -->

    ?? <bean id="mathImp" class="aop.MathImp"/>

    ?

    ?? <!-- this is the actual advice itself -->

    ?? <bean id="logger" class="aop.LogAdvice1"/>

    ?

    ?? <aop:config>

    ????? <aop:aspect ref="logger">

    ?

    ???????? <aop:pointcut id="addLog"

    ??????????????????? expression="execution(* aop.MathImp.*(..)) and target(imp) and JoinPoint(jp)"? />

    ?

    ???????? <aop:before pointcut-ref="addLog"

    ????????????????? method="log" arg-names="jp,imp" />

    ?

    ????? </aop:aspect>

    ?? </aop:config>

    ?

    </beans>

    測試

    package aop;

    ?

    import org.springframework.context.support.AbstractApplicationContext;

    import org.springframework.context.support.FileSystemXmlApplicationContext;

    ?

    /**

    ?* @author Administrator

    ?*

    ?* TODO To change the template for this generated type comment go to

    ?* Window - Preferences - Java - Code Style - Code Templates

    ?*/

    public class Test {

    ?

    ?????? public static void main(String[] args) {

    ????????????? AbstractApplicationContext context=new FileSystemXmlApplicationContext("aop2.xml");

    ????????????? //Math math=(Math) context.getBean("math");

    ????????????? MathImp math=(MathImp) context.getBean("mathImp");

    ????????????? math.add(1,2);

    ????????????? math.addtest(3,4);

    ????????????? math.sub(5,6);

    ?????? }

    }

    posted on 2007-02-26 17:57 超越巔峰 閱讀(3944) 評論(1)  編輯  收藏 所屬分類: Java EE

    評論

    # re: Spring2 AOP在使用XML配置時如何獲得target及JoinPoint 2007-03-30 18:45 itspy

    good!!!  回復  更多評論   

    導航

    統計

    常用鏈接

    留言簿(12)

    隨筆分類(54)

    隨筆檔案(59)

    文章分類(2)

    文章檔案(1)

    相冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲国产av玩弄放荡人妇| 亚洲视频一区在线观看| 亚洲午夜精品久久久久久app| 抽搐一进一出gif免费视频| 亚洲精品亚洲人成在线观看下载| 国产亚洲人成在线影院| 国产午夜免费福利红片| 老司机午夜免费视频| 亚洲人成网站观看在线播放| 99精品视频在线观看免费| 亚洲日韩精品一区二区三区无码 | 国产黄色片免费看| 亚洲中文字幕丝袜制服一区| 国产福利免费视频| 国产精品亚洲产品一区二区三区 | 成人性生交大片免费看午夜a| 亚洲综合色7777情网站777| 青青久在线视频免费观看| 亚洲AV无码一区二区一二区| 免费在线观看理论片| 久久国产乱子伦精品免费午夜| 亚洲AV无码第一区二区三区 | 国产AV无码专区亚洲AV蜜芽| 国产免费av片在线播放| 又硬又粗又长又爽免费看 | 亚洲中文字幕久久精品无码喷水| 最近2019中文免费字幕在线观看| 亚洲日本一区二区三区| 亚色九九九全国免费视频| 男男gay做爽爽免费视频| 亚洲精品成人片在线观看精品字幕| 色欲色香天天天综合网站免费| 亚洲中文字幕AV在天堂| 免费a级毛片大学生免费观看| 成全在线观看免费观看大全| 亚洲人成网站在线观看播放动漫| 国产免费啪嗒啪嗒视频看看| 久久久久久久99精品免费| 亚洲国产AV一区二区三区四区 | 一二三四在线观看免费高清中文在线观看 | 久久精品国产精品亚洲|