<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 閱讀(409) 評論(0)  編輯  收藏 所屬分類: spring
    主站蜘蛛池模板: 国产亚洲精品成人AA片新蒲金| 全黄性性激高免费视频| 亚洲精品无码MV在线观看 | 亚洲人成色7777在线观看| 岛国精品一区免费视频在线观看 | 国产精品亚洲五月天高清| 日日AV拍夜夜添久久免费| 亚洲AV无码专区国产乱码不卡| 在线看片人成视频免费无遮挡| 亚洲中文字幕乱码AV波多JI| 四虎影院免费在线播放| 另类图片亚洲校园小说区| 亚洲av无码成人精品区在线播放| 一本久久A久久免费精品不卡 | 亚洲国产精品久久人人爱| 国产成在线观看免费视频| 亚洲中文字幕乱码一区| 国产91在线免费| 国产免费人成视频尤勿视频| 国产精品亚洲а∨无码播放| 最近中文字幕无免费| 亚洲色偷偷色噜噜狠狠99网| va亚洲va日韩不卡在线观看| 亚洲电影在线播放| 女性自慰aⅴ片高清免费| 免费国产污网站在线观看不要卡| 亚洲精品无码专区久久久| 亚洲成人免费网址| 亚洲国产一区二区a毛片| 免费H网站在线观看的| 久久久久亚洲精品无码网址色欲| 久久影视综合亚洲| 国产精品免费一区二区三区| 又黄又爽无遮挡免费视频| 中文精品人人永久免费| 亚洲女人初试黑人巨高清| 亚洲AV日韩精品一区二区三区| 国产好大好硬好爽免费不卡| 亚洲欧美日韩中文高清www777| 国产AV无码专区亚洲AWWW| 一本岛高清v不卡免费一三区|