私のPro Spring学習ノートの二制御反転(IoC)と依存注入(DI)、Spring初歩

3491 ワード

  Pro Spring             (IoC)     (DI), Spring  

       

                 。                   ,         。
                    。

第一:観点
  IoC DI     Martin Fowler(http://martinfowler.com)。  Inversion of Control Containers
 and the Dependency Injection pattern(http://martinfowler.com/articles/injection.html)     
          。           
 http://gigix.blogdriver.com/diary/gigix/inc/DependencyInjection.pdf。
CSDN    Pro Spring         http://book.csdn.net/bookfiles/48/100481401.shtml  。
  ,      Google。                           。

第二:私のまとめ
1>    Service Locator     (     )
             :JNDI, EJB, J2EE     Service Locator 。  Spring       
       Spring  BeanFactory/ApplicationContext 。  。              。
2>        
                   ,      。
3>     
4>Setter  
             , Martin        。Martin             。     
             。Spring          Setter  。   ,Pro Spring        
Setter   
Spring           ,   Setter   。

Pro Spring         Setter     
1>                   ,                。(    ,      
          ,         ,            。      ,         。)
2>           Setter     。(          )
                :              。                  ,
               。
Pro Spring            :
a>       。                 ,           
b>             
c>            。
    ,               Setter             ,           。
3>             。

                    ,  BeanFactory  ,    ,    ,    。    
      .

第三:ルーチン.
1> HelloWorldXmlWithDI.java    xml    。
  1:   XmlBeanFactory
  2:  bean    Bean,   ref      。
2> HelloWorldXmlWithConstructorDI.java        
  1:           
  :ch2    MessageRenderer     ,   setMessageProvider。(            :
      Setter,            。)
3>ConstructorConfusion.java
  :    type         .
4>BeanFactory   
HierarchicalBeanFactoryUsage.java
      :      ,               ,    parent   。       ,  
          。 local           ,     ,   
    org.springframework.beans.factory.BeanDefinitionStoreException
      ,         :http://www.iteye.com/topic/15057。
5>    
CollectionInjection.java
  :       ,map, list, set, Properties          
6>Bean   Bean  
BeanNaming.java
  :Bean    id, name, class       .name      。
7>  /   /   
NonSingleton.java
         :                  。          。           。
 Spring             。
   ,Spring   bean    。     ,      http://www.iteye.com/post/192557
(       。    Your application code must always have explicit knowledge of the Singleton
class in order to obtain the instance—completely removing the ability to code to interfaces.
      :                             —             
    。            :                 。              
   。code to
interfaces    ,  code of interfaces.          ,          。         
   ,      )
   :       ,Spring         ,    ,             。(     )
8>    
autowring/Target.java
        :byName, byType, consturctor, autodetect.
byType     ,         ,               ,    。           ,
    。      Spring Bug,        。
autodetect  byType constructor        。                    ,  byType。
    constructor。
9>      
           。      。   depends-on。depends-on             ,     
                        .
    dependency-check。           Spring   bean                 。
simple:        java           。
objects:         
all:    
10>    
    ,    ,          。