如果這樣配置/spring-ioc-v1/src/main/resources/spring-configs.xml
beans default-lazy-init="false"
容器初始化立即創(chuàng)建對(duì)象
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("spring-configs.xml");
如果這樣配置/spring-ioc-v1/src/main/resources/spring-configs.xml
延遲加載
beans default-lazy-init="true"
//1.1讀取xml文件中的配置信息(xml解析)
//1.2把解析出來(lái)的配置信息進(jìn)行存儲(chǔ)
//這段代碼只寫(xiě)一次
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("spring-configs.xml");
//2.獲取bean對(duì)象(如HelloServcice)
//2.1此對(duì)象從哪里獲取谦趣?(IOC容器-map獲取)
//何時(shí)創(chuàng)建?(需要配置摘悴,是否配置延遲加載)
//如何創(chuàng)建(通過(guò)反射結(jié)束:Class.forName("bean");
//所有類(lèi)都有唯一的字節(jié)碼對(duì)象.class 這個(gè)T就是類(lèi)型
HelloService hService = ctx.getBean("helloService",HelloService.class);//Class<T>這個(gè)時(shí)候創(chuàng)建對(duì)象