BeanFactory容器(更轻量)

XmlBeanFactory 容器类几乎一样,

只不过BeanFactory容器更轻量化,也是采用DI(依赖注入)的方式.

package test;

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

public class MainApp {
	public static void main(String[] args) {
		BeanFactory factory = new XmlBeanFactory(new ClassPathResource("Beans.xml"));
		HelloWorld obj = (HelloWorld)factory.getBean("helloworld");
		obj.getMessage();
	}

}

  

posted on 2018-03-09 13:50  三盛乙烯  阅读(109)  评论(0编辑  收藏  举报

导航