spring 读取applicationContext方式

package com.test;

import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;

public class SpringMain {

/**
* @param args
*/

public static void main(String[] args) {
SpringBean bean = null;
XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource(
"applicationContext.xml"));
bean = (SpringBean)factory.getBean(
"test1");
bean.sayHello();

ApplicationContext act = new ClassPathXmlApplicationContext(
"applicationContext.xml");
bean = (SpringBean)act.getBean(
"test1");
bean.sayHello();

factory = new XmlBeanFactory(new FileSystemResource(
"F:\\ccc\\workspace_zuhe\\Test\\src\\applicationContext.xml"));
bean = (SpringBean)factory.getBean(
"test1");
bean.sayHello();
}

}
lunzi   2008-04-16 02:27:04 评论:0   阅读:1773   引用:0

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

Copyright@2004-2010 powered by YuLog