1. 定义dao、service等接口或类
2. 导入spring的核心jar包
spring-beans.jar
spring-context.jar
spring-core.jar
spring-expression.jar
运行中抛错:java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
需导入依赖jar包:
commons-logging.jar
3.在src路径下创建spring核心配置文件applicationContext.xml
4.在applicationContext.xml配置中管理所有的dao、service
5.测试spring环境是否测试成功
BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml");
//UserService service = new UserService();
UserService service = (UserService)factory.getBean("service");//getBean()方法中的参数名称与xml文档中节点的id属性值大小写保持一致
service.findUser();