Java蜘蛛人 歡迎大家

          歡迎大家 來到我的blog , 如果我身邊的朋友 有什么不懂可以直接來問我 我會細心的幫助你的. 如果網絡上的朋友有什么不懂的 可以加我Java蜘蛛人 QQ48187537
          posts - 54, comments - 192, trackbacks - 0, articles - 1

          Spring AOP advice

          Posted on 2009-02-13 12:25 Java蜘蛛人 --鄭成橋 閱讀(1125) 評論(0)  編輯  收藏

          很很常用的before ,After ........等等


          返回參數的通知全套代碼:
          package com.zcq.dao;

          public interface Person {
              
              
          public String getName(String name,String pass);

          }



          package com.zcq.dao;

          public class PersonImp implements Person {

              
          public String getName(String name, String pass) {
                  System.out.println(
          "hehe");
                  String bb 
          ="aa";
                  
                  
          return bb;
              }


          }



          package com.zcq.dao;

          import org.aspectj.lang.JoinPoint;

          public class AspectClass {
              
              
              
          public String getName(JoinPoint joinPoint,String bb)
              
          {
                   
                  System.out.println(bb);
                  
          return  null;
              }


          }



          <?xml version="1.0" encoding="UTF-8"?>
           
          <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"
                  xmlns:tx
          ="http://www.springframework.org/schema/tx"
                  xsi:schemaLocation
          ="
                      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
                      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
                      
                      
                      
          <bean id="aspectClass" class="com.zcq.dao.AspectClass"></bean>
                      
          <bean  id="personimp" class="com.zcq.dao.PersonImp"></bean>
                      
                      
          <aop:config>
                        
          <aop:aspect id="addAllMethod" ref="aspectClass">
                          
          <aop:pointcut id="addpointcut" expression="execution(public * get*(..))" />
                        
          <aop:after-returning  pointcut-ref="addpointcut" method="getName"  returning="bb" />
                         
          <!--    <aop:after-throwing pointcut-ref="addpointcut" method="getName" throwing="tx"  />  --> 
                        
          </aop:aspect>            
                      
          </aop:config>
          </beans>


          package com.zcq.dao;

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

          public class Test {

              
          /**
               * 
          @param args
               
          */

              
          public static void main(String[] args) {
                  
                  
                  ApplicationContext ctx
          = null;
                  
                  ctx
          = new ClassPathXmlApplicationContext("applicationContext.xml");
                  
                  Person p  
          = (Person)ctx.getBean("personimp");
                  
                  p.getName(
          "name""pass");

                   
              }


          }


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 息烽县| 和平县| 肃北| 油尖旺区| 北川| 绥芬河市| 金溪县| 贺州市| 宁乡县| 安多县| 布拖县| 昌邑市| 平舆县| 清水河县| 康平县| 长武县| 苍溪县| 佳木斯市| 沙湾县| 莲花县| 深水埗区| 永兴县| 尼勒克县| 什邡市| 五河县| 类乌齐县| 桃江县| 游戏| 门头沟区| 长垣县| 金塔县| 东海县| 远安县| 昌吉市| 石嘴山市| 乐亭县| 玛纳斯县| 图片| 思茅市| 赫章县| 郓城县|