spring快速入门(四)
一、在spring快速入门(三)的基础上,我们来了解BeanFactory及配置。
Client
package com.murong.client; import org.springframework.beans.factory.BeanFactory; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.murong.action.UserAction; import com.murong.action.UserActionImpl; public class Client { public static void main(String[] args) { BeanFactory bf = new ClassPathXmlApplicationContext("applicationContext.xml"); UserAction userAction = (UserAction) bf.getBean("userActionImpl"); userAction.addUser("久伴",24); } }
首先BeanFactory是一个接口 ,有不同的实现类、当然还有其他的实现类,比如 ApplicationContext
package com.murong.client; import org.springframework.beans.factory.BeanFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.murong.action.UserAction; import com.murong.action.UserActionImpl; public class Client { public static void main(String[] args) { /*BeanFactory bf = new ClassPathXmlApplicationContext("applicationContext.xml");*/ ApplicationContext bf = new ClassPathXmlApplicationContext("applicationContext.xml"); UserAction userAction = (UserAction) bf.getBean("userActionImpl"); userAction.addUser("久伴",24); } }
人要耐得住寂寞,才能守得住繁华。人生最痛苦的就是拿不起放不下,不属于自己的快乐,及时放手也许是一种解脱,生活中没有谁对谁错,只有适不适合。当发现很多已经改变,更要面对的是事实。