java - 找不到元素 'beans' 的声明。

标签 java xml spring xsd

下面是我的 sdnext-servlet.xml 声明。我收到此错误

"Cannot find the declaration of element '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>  

关于java - 找不到元素 'beans' 的声明。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28878141/

相关文章:

java - 从 5 个骰子掷骰中,生成一个范围 [1 - 100] 内的随机数

java - 当应该返回 true 时 hashset 返回 false

Android 资源链接失败 - Android Studio

java - 如何使用Java查找XML中未封闭的标签?

java - 具有不同字母长度的替换密码

java - 如何打开使用 'ip tuntap' 创建的 tun 设备

c# - 在 C# 中将 Soap XML 解析为对象

java - Mockito mockStatic 无法解析符号

java - 事务回滚时如何返回不同的值?

java - Spring websocket 从多个线程发送消息