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

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

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


    posts - 10,comments - 4,trackbacks - 0

    接口和實現類見LogBeforeAdvice的例子
    package net.blogjava.dodoma.spring.aop;

    import java.lang.reflect.Method;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.springframework.aop.AfterReturningAdvice;

    public class LogAfterAdvice implements AfterReturningAdvice {
    ?protected static final Log log = LogFactory.getLog(LogAfterAdvice.class);
    ?public void afterReturning(Object returnVal, Method m, Object[] args,
    ???Object target) throws Throwable {
    ??// TODO Auto-generated method stub
    ??log.info("in the class "+this.getClass().getName()+"'s method afterReturning()");

    ??log.info("the target class is:" + target.getClass().getName());
    ??log.info("the target method is:" + m.getName());

    ??for (int i = 0; i < args.length; i++) {
    ???log.info("the method's args is:" + args[i]);
    ??}
    ??
    ??log.info("the returnValue is "+returnVal);
    ??//測試,如果返回裝備發生了異常.將如何處理程序流程
    ??//throw new Exception("返回裝備發生異常");
    ?}

    }

    測試代碼

    package net.blogjava.dodoma.spring.aop;

    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.springframework.aop.framework.ProxyFactory;
    import org.springframework.beans.factory.BeanFactory;
    import org.springframework.beans.factory.xml.XmlBeanFactory;
    import org.springframework.core.io.ClassPathResource;
    import org.springframework.core.io.Resource;

    public class HelloTest {
    ?protected static final Log log = LogFactory.getLog(HelloTest.class);

    ?/**
    ? * @param args
    ? * @throws Exception
    ? */
    ?public static void main(String[] args) throws Exception {
    ??// TODO Auto-generated method stub
    ??Resource rs = new ClassPathResource("beans.xml");
    ??BeanFactory bf = new XmlBeanFactory(rs);

    ??HelloI h = (HelloI) bf.getBean("theBean");
    ??log.info("starting...");
    ??try {
    ???log.info(h.sayHello("ma", "bin"));
    ??} catch (Exception e) {
    ???e.printStackTrace();
    ??}
    ??log.info("end...");
    ??
    ??
    ??ProxyFactory factory=new ProxyFactory();
    ??factory.addAdvice(new LogAfterAdvice());
    ??factory.setTarget(new Hello("hello"));
    ??try{
    ??HelloI hi=(HelloI)factory.getProxy();
    ??hi.sayHello("ma","bin");}
    ??catch(Exception e){e.printStackTrace();}
    ?}

    }


    在beans.xml中加入如下代碼
    <bean id="theLogAfterAdvice" class="net.blogjava.dodoma.spring.aop.LogAfterAdvice"/>

    <property name="interceptorNames">
    ????? <list>
    ??????? <value>theLogAfterAdvice</value><!--此時直接使用advice,表明這個類所有的實例,方法,都享受advice的攔截-->
    ?????? </list>?
    </property>

    切入點可省略,如需要的話


    <!--切入點-->
    ? <!--Note: An advisor assembles pointcut and advice-->
    ? <bean id="theBeAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
    ??? <property name="advice">
    ????? <ref local="theLogAfterAdvice"/>
    ??? </property>
    ??? <!--匹配模式-->
    ??? <property name="pattern">
    ????? <value>.*</value>
    ??? </property>
    ? </bean>

    posted on 2006-03-28 12:37 dodoma 閱讀(415) 評論(0)  編輯  收藏 所屬分類: spring
    主站蜘蛛池模板: 亚洲国产精品一区二区成人片国内 | 亚洲精品高清视频| 久久九九免费高清视频| 亚洲乱码中文字幕手机在线| 狼色精品人妻在线视频免费| 国产猛烈高潮尖叫视频免费| 美女免费视频一区二区| 亚洲国产成人久久综合区| 一本一道dvd在线观看免费视频 | 免费a级毛片大学生免费观看| 亚洲精品无码中文久久字幕| 日本免费电影一区| 羞羞网站免费观看| 精品亚洲一区二区三区在线观看| 国产真人无码作爱免费视频| 久久亚洲国产视频| 在线永久免费的视频草莓| 亚洲欧洲日韩国产一区二区三区| 无码视频免费一区二三区| 亚洲αⅴ无码乱码在线观看性色| 免费h黄肉动漫在线观看| 中文字幕乱理片免费完整的| 亚洲国产精品一区| 成年女人毛片免费播放视频m| 校园亚洲春色另类小说合集| 国产日产亚洲系列最新| 一级毛片在线免费观看| 亚洲字幕AV一区二区三区四区| 国产成人高清精品免费软件 | 一级特黄特色的免费大片视频| 亚洲精品无码不卡在线播放HE| 91高清免费国产自产拍2021| 亚洲色无码国产精品网站可下载| 国产又大又长又粗又硬的免费视频 | 久久综合亚洲色HEZYO社区| 最近免费中文字幕大全| 国产精品免费一区二区三区| 亚洲男女一区二区三区| 亚洲精品高清一二区久久| 97视频免费观看2区| 美景之屋4在线未删减免费|