There is no ID/IDREF binding for IDREF 'sessionFactory'

加載spring配置文件時,報如下錯誤:


org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 52 in XML document from class path resource [applicationContext-transcation.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-id.1: There is no ID/IDREF binding for IDREF 'sessionFactory'.

Caused by: org.xml.sax.SAXParseException: cvc-id.1: There is no ID/IDREF binding for IDREF 'sessionFactory'.


看這個意思是找不到bean

原因:我之前是隻有一個applicationContext.xml配置文件,後來模塊化,被拆分成多個配置文件,而有一個地方:


<!-- sessionFactory定義事務管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>


引用類型是<ref local="sessionFactory" /> local 表示只在本文件中找bean

改成<ref bean="sessionFactory" /> 之後,問題解決。

ref bean= 表示在所有applicationContext.xml中找bean

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章