2014-01-31 56 views
3

我想下面的代碼:http://www.dineshonjava.com/2012/12/spring-mvc-with-hibernate-crud-example.html#.Uus0bvnoSGc 的sdnext-servlet.xml中如下:XMLBeanDefinitionStoreException:找不到的聲明元素 '豆'

<beans xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemalocation=" 
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd 
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> 

<context:property-placeholder location="classpath:resources/database.properties"> 
</context:property-placeholder> 
<context:component-scan base-package="com.dineshonjava"> 
</context:component-scan> 

<tx:annotation-driven transaction-manager="hibernateTransactionManager"> 
</tx:annotation-driven> 

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="jspViewResolver"> 
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property> 
<property name="prefix" value="/WEB-INF/views/"></property> 
<property name="suffix" value=".jsp"></property> 
</bean> 

<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="dataSource"> 
<property name="driverClassName" value="${database.driver}"></property> 
<property name="url" value="${database.url}"></property> 
<property name="username" value="${database.user}"></property> 
<property name="password" value="${database.password}"></property> 
</bean> 

<bean class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" id="sessionFactory"> 
<property name="dataSource" ref="dataSource"></property> 
<property name="annotatedClasses"> 
    <list> 
    <value>com.dineshonjava.model.Employee</value> 
    </list> 
</property> 
<property name="hibernateProperties"> 
<props> 
    <prop key="hibernate.dialect">${hibernate.dialect}</prop> 
    <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> 
    <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto} </prop>  
     </props> 
     </property> 
</bean> 

    <bean class="org.springframework.orm.hibernate3.HibernateTransactionManager" id="hibernateTransactionManager"> 
<property name="sessionFactory" ref="sessionFactory"></property> 
    </bean> 
</beans> 

我得到異常

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 12 in XML document from ServletContext resource [/WEB-INF/config/sdnext-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 12; columnNumber: 62; cvc-elt.1: Cannot find the declaration of element 'beans'. 

我無法弄清楚什麼是錯的。請幫助

回答

5

XML命名空間定義更改爲這個

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" 
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd 
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> 

,它應該工作

問題是與您的xsi:schemalocation定義錯字與L這應該是資本,只那麼它會識別標籤。

+0

變更至線7號:還是一樣的錯誤 – SKaul

+0

和你有什麼改變? –

+0

我按照建議使用了xml命名空間定義,但錯誤沒有消失。名稱空間定義的最後一行仍然是一個例外 – SKaul

0

這爲我工作:

需要更改默認的命名空間象下面這樣:

<beans:beans xmlns="http://www.springframework.org/schema/security" 
     xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/security 
     http://www.springframework.org/schema/security/spring-security-3.2.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context.xsd" 
     xmlns:context="http://www.springframework.org/schema/context"> 

    <mvc:resources mapping="/scripts/**" location="/scripts/" /> 
    <mvc:resources mapping="/resources/**" location="/resources/" /> 
    <context:component-scan base-package="com.dewsoftware.webapp" /> 

</beans:beans> 
相關問題