1
我對Spring組件掃描有一些疑問。組件掃描:用Spring加載bean
我想加載我的「my.package.test」中的所有bean以及「my.package」中的一個bean。 要做到這一點,我寫了這個XML:
<context:component-scan
base-package="my.package.test" use-default-filters="false" >
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>
<context:include-filter type="annotation" expression="org.springframework.stereotype.Component"/>
<context:include-filter type="assignable" expression="my.package.TestBean" />
</context:component-scan>
我所有的豆子「my.package.test」很好加載,但我testBean就沒有加載,我有沒有匹配的bean的錯誤。 我的TestBean標註的是@Component。
我不明白爲什麼它沒有加載。
感謝您的幫助。
是的Spring掃描「my.package.test」下的所有內容,但我在「my.package」中有幾個bean,我希望它只掃描一個TestBean。我相信這一行允許: 因爲我明確聲明瞭一個bean –
Kiva
如果你只是想要加載一個bean,只需將它定義爲一個bean比掃描它:''。組件掃描用於自動掃描軟件包並創建bean。 –
是的,我知道我可以這樣做,但是如果不創建特定的bean,這個標籤的目標是什麼(context:include-filter type =「assignable」)? – Kiva