Spring-第四章:注入

1.什么是注入

通过Spring工厂计配置文件,为所创建对象的成员变量赋值

1.1为什么需要注入

通过编码的方式,为成员变量进行赋值,存在耦合

如何进行注入【开发步骤】

  • 类的成员变量提供set get方法
  • 配置Spring的配置文件
 <bean id="student" class="Dao.student">
     <property name="name">
         <value>lty</value>
     </property>
     <property name="age">
         <value>23</value>
     </property>
 </bean>

注入的好处

解耦合

2.Spring注入的原理分析(简易版)

Spring通过底层调用对象属性对应的set方法,完成成员变量的赋值,这种方式我们也称为set注入
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/m0_47298981/article/details/107566243