BeanFactory容器(更轻量)

XmlBeanFactory 容器类几乎一样,

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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   三盛乙烯  阅读(109)  评论(0编辑  收藏  举报

努力加载评论中...

导航

点击右上角即可分享
微信分享提示