Spring相关概念和类

   1、IOC

            inverse of control    控制反转   反转了创建对象的方式

           以前:new 对象,管理和维护开发者来完成

           Spring:Spring创建和管理,维护对象,开发者只需要使用该对象。

 2、DI(Dependecy Injection): 依赖注入

         DI是为IOC做支持的  

         IOC创建的对象的内容是null,所以我们要注入内容

 3、BeanFactory    ApplicationContext,classPathXMLApplicationContext

         最原始的接口

         是BeanFactory的实现类

         是ApplicationContext的实现类,用于加载spring的配置文件

二、Spring的bean的创建方式(3种)

    1 、无参构造方法  <bean name=" " class="包名+类名">

           2 、静态工厂方式   <bean   name="  " class="包名+类名(工厂的类名)"  factory-method="工厂中的静态方法">

           3、实例工厂方式    首先先创建工厂对象

                                 <bean name="factory"   class="包名+类名(工厂类的名字)">

                                  <bean  name=" "   factory-bean="factory "   factory-method="工厂中的创建对象的方法"> 

三、Spring属性注入方式(DI)

        1、构造方法注入

     <constructor-arg name="" value=""></constructor-arg>(基本类型)

     <constructor-arg name="" ref=""></constructor-arg>     (引用类型) 

   指定参数位置    index  从0开始

        2、set方法注入

         <property name=""   value=""></property>(基本类型)

         <property  name=""  ref=""></property>(引用类型)

        3、p名称空间注入

            1、引入名称空间

            2、使用:

           3、基本类型:   p:属性名="值"   引用类型:  p:属性名-ref="值"

        4、spel注入

          #{表达式}    字符串的值要用单引号括起来

          也可以用对象点出来    #{user1.user.id}  都是 value

 

四、Spring复杂类型注入(4种)(DI)

         array:<array name="">  

                   <value></value>

                   <value></value>

                     </array>

 

         list:<list name="">  

                   <value></value>   

                    <ref   bean=""></ref>

                 </list>

 

 

 

         map:  <map name="">

                         <entry key="" value=""></entry>

                         <entry key="" value-ref=""></entry>

                      </map>

         

       properties:<property  name="">

                                <props>

                                       <prop  key="">value</prop>

                                        <prop  key="">value</prop>

                              </props>

                         </property>

                      

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

      

 

                            

posted on 2018-01-23 20:43  Leroy_罗先生  阅读(408)  评论(0编辑  收藏  举报