spring容器管理bean

没有spring容器管理bean,我们获取一个对象,需要手动new

当有了spring管理,我们需要的bean是直接从spring容器中获取

有一个applicationContext.xml(用来配置bean),需要有约束头

然后是加载这个配置文件

加载完后,启动容器,让容器读取配置文件,接着就是从容器中获取bean

步骤:

1.准备jar包 spring-beans-4.1.2.RELEASE.jar spring-core-4.1.2.RELEASE.jar 报错再添加: com.springsource.org.apache.commons.logging-1.1.1.jar

2.开发HelloWorld程序

3.在applicationContext.xml中完成配置(xsd-config.html)

4.启动容器

5.从容器中得到bean

6.调用bean响应的方法

报ClassNotFound,一般是两种情况,要么是没导包,要么是导错包

约束头有两种,一种dtd,一种是schema

猜你喜欢

转载自www.cnblogs.com/Girlir/p/8910513.html