spring核心容器,是spring框架的基石,任何spring项目运行时都会生成一个容器,把项目运行时须要的对象所有管理起来。建立对象,销毁对象,对象关系的依赖。能够将spring看做是服务器与应用程序的中间管理软件spring
spring主要依靠IOC容器建立bean来管理对象,IOC容器一共有三种方式建立bean服务器
1.构造方法建立bean框架
无参构造建立bean:在spring.xml配置文件中配置bean标签 spa
<bean id="student" class="实体类全限定名"/>
有参构造建立bean:code
<bean id="student" class="day0228.entity.student">
<!-- 配置构造方法参数,index参数的索引,value是参数值 -->
<constructor-arg index="" value=""/>
<constructor-arg index="" value=""/>
</bean>
2.静态工厂建立beanxml
建立一个工厂,提供一个静态方法返回对象对象
public class StudentFactory { //提供一个静态方法建立Student对象 public static Student createStudent() { return new Student(22,"张三"); } }
配置spring.xml配置文件blog
//class:工厂类全限定名,factory-method:静态方法名
<bean id="student" class="day0228.factory.StudentFactory" factory-method="createStudent"/>
3.动态工厂建立bean索引
建立一个实例工厂,提供一个实例方法返回对象it
public class StudentFactory { //提供一个实例方法建立Student对象 public Student createStudent() { return new Student(22,"张三"); } }
配置spring.xml配置文件
<bean id="studentFactory" class="day0228.factory.StudentFactory"/> <!-- factory-bean配置工厂对象,factory-method配置工厂方法 --> <bean id="student" factory-bean="studentFactory" factory-method="createStudent"/>