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);
}
}
上一篇:数据库开发基础-SQl Server 聚合函数、数学函数、字符串函数、时间日期函数


下一篇:mysql 常用获取时间sql语句