随笔-295  评论-26  文章-1  trackbacks-0

package com.springinaction.chapter01.knight;

import java.lang.reflect.Method;

import org.apache.log4j.Logger;
import org.springframework.aop.MethodBeforeAdvice;


public class MinstrelAdvice implements MethodBeforeAdvice {
  public void before(Method method, Object[] args, Object target)
      throws Throwable {

    Knight knight = (Knight) target;
   
    Logger song = Logger.getLogger(target.getClass());
   
    song.debug("Brave " + knight.getName() + " did " + method.getName());
  }
}

package com.springinaction.chapter01.knight;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.FileSystemResource;
public class KnightApp {
  private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
      .getLogger(KnightApp.class);
 
  public static void main(String[] args) throws Exception {
    LOGGER.debug("Running KnightApp");
    ApplicationContext m;
    BeanFactory factory =
        new XmlBeanFactory(new FileSystemResource("knight.xml"));

///有XmlBeanFactory来负责具体的实现     knight.xml必须要保存在项目的总目录下面
Knight knight =
        (Knight) factory.getBean("knight");

    knight.embarkOnQuest();
    System.out.println("ok");
    LOGGER.debug("KnightApp Finished");
  }
}



大盘预测 国富论
posted on 2007-08-27 16:11 华梦行 阅读(545) 评论(0)  编辑  收藏 所属分类: Spring

只有注册用户登录后才能发表评论。


网站导航: