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來(lái)負(fù)責(zé)具體的實(shí)現(xiàn)???? knight.xml必須要保存在項(xiàng)目的總目錄下面
Knight knight =
??????? (Knight) factory.getBean("knight");
??? knight.embarkOnQuest();
??? System.out.println("ok");
??? LOGGER.debug("KnightApp Finished");
? }
}
大盤(pán)預(yù)測(cè)
國(guó)富論
posted on 2007-08-27 16:11
華夢(mèng)行 閱讀(548)
評(píng)論(0) 編輯 收藏 所屬分類(lèi):
Spring