spring学习三

1: Spring的IOC容器:

         IOC容器为管理对象之间的依赖关系提供了基础功能。

        A:BeanFactory:

        B:ApplicationContext(继承自BeanFactory,功能更多):  

               有3个实现类:

     ClassPathXmlApplicationContext :  classpath是指 WEB-INF文件夹下的classes目录 。

     FileSystemXmlApplicationContext: 用绝对路径找,不推荐。

     XmlWebApplicationContext :    专为web设计的 。

 2: 四种依赖注入: 

                (1) 设置注入(setter):

                (2) 构造方法注入:

          (3)  接口注入:

    (4)  工厂方法注入:

              前两种用的多。

3: forName( )  Vs   getClass

        java.lang.Class代表java应用程序在运行时加载的类或接口实例,Class类的对象是由JVM生成。

        Object的getClass() 方法可以获取对象的class对象,然后通过class对象可以获取类的信息。

                              Class<?> aa = Class.forName("Integer");   // 通过类的字符串得到类

        Integer in = new Integer();
              Class<? extends Integer> bb = in.getClass();  // 通过对象得到类信息。

         有的时候由一个名称来获得类,这个时候可以用forName() 来动态的加载类。

 4:   getDeclaredMethod()    VS   getMethod() 

  getDeclaredMethod*()获取的是类自身声明的所有方法,包含public、protected和private方法。

  getMethod*()获取的是类的所有共有方法,这就包括自身的所有public方法,和从基类继承的、从接口实现的所有public方法。

5:   获得类中成员变量和成员函数的方法:

  获得类中成员的函数:     

            Field getField(String name)            // public 成员

            Field[] getFields()                             // public 成员

            Field getField(String name)           // all 成员

            Field[] getDeclaredFields()            // all 成员

    获得类的函数的方法:

       Method getMethod(String name, Class[] paramTypes)   //根据方法名和参数来获得

       Method[]  getMethod():   获得类中所有公共方法。

       Method getDeclaredMethod(String name, Class[] paramTypes)  //   不包括从父类继承的方法。

       Method[] getDeclaredMethod()             不包括父类继承的方法。

6:  Spring 集合注入:

                              list  /  map  /  set /  properties

7:  parent 用处:

parent 用处: 继承,父类中已经注入的属性,不需重复注入。
<alias name="tskdefaultWsAuthenticationProvider" alias="wsAuthenticationProvider" />
    <bean id="tskdefaultWsAuthenticationProvider"
          class="com.fivestar.tsk.service.TSKCoreAuthenticationProvider"  parent = "defaultWsAuthenticationProvider">    
    </bean>

8: bean的ID是否有可能重复?

                是的,可以重复,重复的话会有覆盖的行为。 

9: parent:   父亲中已经注入的属性不需要再重复注入;

        merge = true:   表示集合和父集合的合并

<bean id="carouselProductConverter" parent="defaultProductConverter">
        <property name="populators">
            <list merge="true">
                <ref bean="productPricePopulator"/>
            </list>
        </property>
</bean>

10: 集合中的元素可以是其他的bean

 <bean id="fsProductModel2FSProductDataConverter" parent="logExecutionTimeConverter">
        <property name="targetClass" value="com.fivestar.tsk.product.data.FSProductData" />
        <property name="populators">
            <list>
                <ref bean="fsProductBasicPopulator" />
                <ref bean="fsProductPublishInfoPopulator" />
                <ref bean="fsProductDisplayAttributePopulator" />
                <ref bean="fsProductSalesAttributePopulator" />
                <ref bean="fsProductPromotionPopulator" />
                <ref bean="fsExtendWarrantProductPopulator" />
            </list>
        </property>
    </bean>

11:  abstract="true" 表示不用实例化(目的是让子类的bean继承)

       <bean id="logExecutionTimeConverter"

   class="com.fivestar.tsk.facades.converters.LogExecutionTimeConverter"

      abstract="true" />

原文地址:https://www.cnblogs.com/liufei1983/p/7545733.html