Spring內(nèi)核研究-管理bean之間的關(guān)系三(自動(dòng)裝配)
Spring BeanFactory提供了類(lèi)似pico container中自動(dòng)裝配組件依賴(lài)的對(duì)象的功能。自動(dòng)裝配能應(yīng)用在每個(gè)組件上,可以為一些組件定義自動(dòng)裝配,而另一些組件則不使用。no
byName
SHAPE \* MERGEFORMAT
|
|
按照bean定義的名稱(chēng)自動(dòng)裝配 |

SHAPE \* MERGEFORMAT
|
這個(gè)Bean將被注入到dao中 |

byType
SHAPE \* MERGEFORMAT
|
|
按照bean定義的類(lèi)型自動(dòng)裝配 |

SHAPE \* MERGEFORMAT
|
這個(gè)Bean將被注入到dao中 |

SHAPE \* MERGEFORMAT
|

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dao' defined in class path resource [research/spring/beanfactory/ch3/context.xml]: Unsatisfied dependency expressed through bean property 'database': There are 2 beans of type [class research.spring.beanfactory.ch3.Database] for autowire by type. There should have been 1 to be able to autowire property 'database' of bean 'dao'...
constructor其實(shí)時(shí)按byType的方式進(jìn)行構(gòu)造函數(shù)的注入。
SHAPE \* MERGEFORMAT
|
|
按照bean定義的類(lèi)型自動(dòng)裝配 |

constructor裝配方式不關(guān)心構(gòu)造參數(shù)的順序,無(wú)論構(gòu)造函數(shù)參數(shù)的順序如何Spring都會(huì)按類(lèi)型匹配到正確的合作者進(jìn)行注入。
autodetect
posted on 2007-04-09 03:01 crazy zerlot 閱讀(349) 評(píng)論(0) 編輯 收藏