2014-01-14 92 views
0

我在我的Spring應用程序上配置了hibernate,並在我的servlet-context文件中獲得了以下錯誤。在我的Spring應用程序中配置休眠問題

我有什麼搞砸的XML文件?

錯誤如下:

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:38 線從ServletContext的資源 [XML文檔中/WEB-INF/servlet-context.xml ] 是無效的;嵌套的異常是 org.xml.sax.SAXParseException; lineNumber:38; columnNumber:109; cvc-complex-type.2.4.a:從 元素'bean'開始找到無效內容。一個 '{ 「http://www.springframework.org/schema/beans 」:進口, 「 http://www.springframework.org/schema/beans 」:別名, 「 http://www.springframework.org/schema/beans 」:豆, WC [##等:「 http://www.springframework.org/schema/beans 」], 「 http://www.springframework.org/schema/beans」:豆}' 的預期。

我的servlet-context.xml的

<?xml version="1.0" encoding="UTF-8"?> 
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:task="http://www.springframework.org/schema/task" xmlns:context="http://www.springframework.org/schema/context" 
xmlns:util="http://www.springframework.org/schema/util" xmlns:p="http://www.springframework.org/schema/p" 
xmlns:tx="http://www.springframework.org/schema/tx" 
xsi:schemaLocation=" 
http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
http://www.springframework.org/schema/task 
http://www.springframework.org/schema/task/spring-task-4.0.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-4.0.xsd 
http://www.springframework.org/schema/util 
http://www.springframework.org/schema/util/spring-util-4.0.xsd 
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd 
"> 

<!-- DispatcherServlet Context: defines this servlet's request-processing 
    infrastructure --> 

<!-- Handles HTTP GET requests for /resources/** by efficiently serving 
    up static resources in the ${webappRoot}/resources directory --> 
<!-- <resources mapping="/resources/**" location="/images/" /> --> 

<!-- Resolves views selected for rendering by @Controllers to .jsp resources 
    in the /WEB-INF/views directory --> 
<beans:bean 
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <beans:property name="prefix" value="/WEB-INF/jsp/" /> 
    <beans:property name="suffix" value=".jsp" /> 
</beans:bean> 

<beans:import resource="classpath:/WEB-INF/controllers.xml" /> 
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
    <property name="basename" value="classpath:messages" /> 
    <property name="defaultEncoding" value="UTF-8" /> 
</bean> 
<bean id="propertyConfigurer" 
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" 
    p:location="/WEB-INF/jdbc.properties" > 
    </bean> 

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
    destroy-method="close" p:driverClassName="${jdbc.driverClassName}" 
    p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}"> 
</bean> 


<bean id="sessionFactory" 
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 
    <property name="dataSource" ref="dataSource" /> 
    <property name="configLocation"> 
     <value>classpath:hibernate.cfg.xml</value> 
    </property> 
    <property name="configurationClass"> 
     <value>org.hibernate.cfg.AnnotationConfiguration</value> 
    </property> 
    <property name="hibernateProperties"> 
     <props> 
      <prop key="hibernate.dialect">${jdbc.dialect}</prop> 
      <prop key="hibernate.show_sql">true</prop> 
     </props> 
    </property> 
</bean> 

<tx:annotation-driven /> 
<bean id="transactionManager" 
    class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
    <property name="sessionFactory" ref="sessionFactory" /> 
</bean> 
</beans:beans> 

回答

1

你開始使用命名空間前綴

<beans:bean... 

<beans:property... 

但隨後停止

<bean... 

<property... 

爲什麼?任何屬於beans名稱空間的元素都需要以beans作爲前綴。

或者,您可以將beans設爲您的default namespace,以便您不必爲屬於它的所有元素加上前綴。