spring xmlBeanFactory

spring xmlBeanFactory

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");
  }
}



大盘预测

你可能感兴趣的:(spring xmlBeanFactory)