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

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

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

    posts - 165, comments - 198, trackbacks - 0, articles - 1
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    spring AspectJ 基本使用

    Posted on 2008-05-08 10:08 G_G 閱讀(4339) 評論(1)  編輯  收藏 所屬分類: SpringAOP
    我的aop 基礎
    spring 實際使用 (這就使用一個例子說明)

    測試類以及結果:
    package?unit;

    import?org.springframework.context.ApplicationContext;
    import?org.springframework.context.support.ClassPathXmlApplicationContext;

    import?bean.HelloService;

    public?class?Main?{
    ????
    public?static?void?main(String[]?args)?{
    ???????????ApplicationContext?context?
    =?new?ClassPathXmlApplicationContext(??????
    ???????????????????
    "beans.xml");????
    ???????????HelloService?service?
    =?(HelloService)?context.getBean("helloService");????
    ???????????service.annotationAop();
    ???????????
    ???????????System.out.println();
    ???????????
    ???????????service.xmlAop();
    ???????????
    ????}
    }
    結果:
    ?annotationAop//正常方法運行
    aop--AspectJ!?//
    annotation攔截

    ?xmlAop?
    //正常方法運行
    ?aop--XmlAop! //配置攔截



    use jar
    • --aspectjrt.jar
    • --aspectjweaver.jar
    • --acglib-nodep-2.1_3.jar
    • --commons-logging.jar
    • --spring.jar
    • --spring-aspects.jar
    XML配置
    <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.xsd?????????
    ???????????????????http://www.springframework.org/schema/aop?????????
    ???????????????????http://www.springframework.org/schema/aop/spring-aop.xsd"
    >
    ????????
    ????????
    <!--?測試使用類?分別由?方法?annotationAop/xmlAop?-->
    ????????
    <bean?id="helloService"???????
    ????????????class
    ="bean.HelloService"/>????
    ????????
    ????????????
    ????????
    <!--?annotation?aop?攔截?使用@Aspect?
    ????????????@Pointcut("execution(*?annotationAop(..))")??
    ????????????@AfterReturning("mainMethod()")??
    ????????
    -->
    ????????
    <bean?id="xmlAop"?
    ????????????class
    ="aop.AnnotationAspectJ"/>
    ????????
    <aop:aspectj-autoproxy/>????
    ????????
    ????????
    ????????
    <!--?xml?aop??配置文件攔截?-->
    ????????
    <bean?id="XmlAspectJ"???????
    ????????????class
    ="aop.XmlAspectJ"/>
    ????????
    <aop:config>?????
    ?????????????
    <aop:aspect?ref="XmlAspectJ">
    ?????????????????
    <aop:pointcut?id="mainMethod"?expression="execution(*?xmlAop(..))"/>????
    ?????????????????
    <aop:after-returning?pointcut-ref="mainMethod"?method="goXmlAop"/>?????
    ?????????????
    </aop:aspect>???
    ?????????
    </aop:config>????
    ????????????
    </beans>

    HelloService.java
    package?bean;

    public?class?HelloService?{??
    ????
    public?void?annotationAop()?{????
    ????????System.out.println(
    "?annotationAop?");
    ????}
    ????
    ????
    public?void?xmlAop(){
    ????????System.out.println(
    "?xmlAop?");
    ????}
    }

    AnnotationAspectJ.java
    package?aop;

    import?org.aspectj.lang.annotation.AfterReturning;
    import?org.aspectj.lang.annotation.Aspect;
    import?org.aspectj.lang.annotation.Pointcut;

    @Aspect
    public?class?AnnotationAspectJ?{??
    ????@Pointcut(
    "execution(*?annotationAop(..))")??
    ????
    public?void?mainMethod()?{}??
    ????
    ????@AfterReturning(
    "mainMethod()")??
    ????
    public?void?sayHello()?{????
    ????????System.out.println(
    "aop--AspectJ!");??
    ????}
    }

    XmlAspectJ.java
    package?aop;

    public?class?XmlAspectJ?{
    ????
    public?void?goXmlAop(){
    ????????System.out.println(
    "?aop--XmlAop!?");
    ????}
    }














    評論

    # re: spring AspectJ 基本使用  回復  更多評論   

    2009-12-13 14:12 by 什么玩意亂糟糟的
    你寫的這是什么啊
    主站蜘蛛池模板: 一级毛片视频免费观看| 少妇亚洲免费精品| 亚洲三级在线免费观看| 美女视频免费看一区二区| 毛片在线全部免费观看| 日韩高清免费观看| 亚洲成色999久久网站| 日本亚洲欧美色视频在线播放| a级毛片高清免费视频就| 在线看片无码永久免费视频| 伊人久久亚洲综合| 亚洲免费综合色在线视频| 国产精品区免费视频| 亚洲AV成人潮喷综合网| 中文字幕亚洲免费无线观看日本| 亚洲精品无码成人| 可以免费观看的一级毛片| 亚洲成人一级电影| 日韩插啊免费视频在线观看| 免费中文字幕在线观看| 久久www免费人成精品香蕉| 日韩精品视频免费观看| 又硬又粗又长又爽免费看| 亚洲乱码中文字幕综合| 亚洲国产成人久久精品app| 国产高清不卡免费视频| 亚洲成a人片7777| 国产一级淫片免费播放| 亚洲av日韩av永久在线观看| 国产成人精品日本亚洲专区 | 男人的天堂av亚洲一区2区| 五月婷婷亚洲综合| 午夜免费福利片观看| 亚洲成a人片在线观看无码专区| 一级做a毛片免费视频| 亚洲日本在线观看| 99re免费99re在线视频手机版| 亚洲一卡2卡3卡4卡国产网站| yy6080久久亚洲精品| 久久国产乱子伦精品免费一 | 久久亚洲AV无码西西人体|