名词解释
一。ioc(inverse of controll ) 控制反转: 所谓控制反转就是把创建对象(bean),和维护对象(bean)的关系的权利从程序中转移到spring的容器(applicationContext.xml),而程序本身不再维护.
二。 di(dependency injection) 依赖注入: 实际上di和ioc是同一个概念,spring设计者认为di更准确表示spring核心技术
bean作用域
scope=""
作用域 | 描述 |
---|---|
在每个Spring IoC容器中一个bean定义对应一个对象实例。 | |
一个bean定义对应多个对象实例。 | |
在一次HTTP请求中,一个bean定义对应一个实例;即每次HTTP请求将会有各自的bean实例, 它们依据某个bean定义创建而成。该作用域仅在基于web的Spring | |
在一个HTTP | |
在一个全局的HTTP |
<bean id="changeLetter" class="cn.hyl.hsp.inter.UpperLetter" scope="singleton">
<property name="str" value="ABRTY" />
</bean>
<!--[if !supportLists]-->u <!--[endif]-->三种获取ApplicationContext 对象引用的方法
<!--[if !supportLists]-->1. <!--[endif]-->ClassPathXmlApplicationContext -> 通过类路径
<!--[if !supportLists]-->2. <!--[endif]-->FileSystemXmlApplicationContext -> 通过文件路径
举例:
ApplicationContext ac=new FileSystemXmlApplicationContext("文件路径beans.xml / applicationContext.xml");
<!--[if !supportLists]-->3. <!--[endif]-->XmlWebApplicationContext