在進行 SSI整合時,老是報下邊的錯誤: nested exception is java.lang.IllegalArgumentException: Property 'sqlMapClient' is required java
詳細的錯誤信息以下:spring
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personDao' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlMapClient' is requiredsql
在配置文件applicationContext中查看後發現配置中沒有properties標籤,很明顯是沒有將sqlMapClien注入到personDao中:app
<bean id="personDao" class="com.zaj.dao.PersonDao"/>
正常思惟就是將已經註冊的sqlMapClient注入到personDao中,修改以下:ide
<bean id="personDao" class="com.zaj.dao.PersonDao"> <property name="sqlMapClient" ref="sqlMapClient"></property> </bean>
試運行,沒錯,運行正確,錯誤沒了。但是我對照事例中的xml文件,明明是沒有這個properties的,這究竟是爲何?仔細對比,發如今事例的xml文件頭裏邊,有一個屬性,以下:學習
default-autowire="byName"
按着事例的樣子,把屬性加上,註釋掉剛纔新加的properties,再次運行,果真能夠,看到byName,想起來原來好像聽馬哥(馬士兵)說過,有byName和byType自動加載的屬性,基於學習起見,找出spring的參考文檔,找啊找,終於找到下邊的內容:ui
Optional attribute controlling whether to "autowire" bean properties. This is an automagical process in which bean references don't need to be coded explicitly in the XML bean definition file, but Spring works out dependencies. There are 5 modes: 1. "no" No automagical wiring. Bean references must be defined in the XML file via the <ref> element. We recommend this in most cases as it makes documentation more explicit. Autowiring by property name. If a bean of class Cat exposes a dog property, Spring will try to set this to the value of the bean "dog" in the current factory. 3. "byType" Autowiring if there is exactly one bean of the property type in the bean factory. If there is more than one, a fatal error is raised, and you can't use byType autowiring for that bean. If there is none, nothing special happens; use dependency-check="objects" to raise an error in that case. 4. "constructor" Analogous to "byType" for constructor arguments. If there isn't exactly one bean of the constructor argument type in the bean factory, a fatal error is raised. 5. "autodetect" Chooses "constructor" or "byType" through introspection of the bean class. If a default constructor is found, "byType" gets applied. The latter two are similar to PicoContainer and make bean factories simple to configure for small namespaces, but doesn't work as well as standard Spring behaviour for bigger applications. Note that explicit dependencies, i.e. "property" and "constructor-arg" elements, always override autowiring. Autowire behavior can be combined with dependency checking, which will be performed after all autowiring has been completed. Note: This attribute will not be inherited by child bean definitions. Hence, it needs to be specified per concrete bean definition.意思是若是被bean中暴露出來一個bean後,若是找不到被暴露出來的這個bean,不會報錯,可是若是使用dependency-check="objects"則會報錯,可是我是什麼都沒有暴露他出的錯誤啊,又仔細看發現mode ‘no’,人家明顯寫着The traditional Spring default.說默認是no,就是說默認不會自動wire,必須在xml文件中手動注入,手動鏈接,這下就明白了,原來沒寫default-autowire="byName"的時候是找不到sqlMapClient的,由於默認使用的是no!後來我就試了一下byType徹底沒有影響啊,估計是由於個人id都是惟一的,其餘的就沒有再試了,有興趣你們能夠本身試。 這下就對這個錯誤瞭解比較深了,也對spring配置有所瞭解,但願對遇見這個錯誤的同窗有所幫助。