簡體   English   中英

找不到元素'beans'的聲明。

[英]Cannot find the declaration of element 'beans'.

以下是我的sdnext-servlet.xml聲明。 我收到此錯誤

“找不到元素'beans'的聲明”

即使我在線。 我正在使用Spring 3.0.1。

這是sdnext-servlet.xml:

<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">
    </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.dto.Causer</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>  

它是schemaLocation而不是schemalocation

解決該錯誤后,請關閉context:property-placeholder和其他一些類似元素,而不要讓其內容包含換行符。

這是您更新的有效XML:

<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:component-scan base-package="com"/>

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

  <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.dto.Causer</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>  

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM