簡體   English   中英

在Spring應用程序中遇到錯誤:cvc-elt.1:找不到元素'beans'的聲明

[英]Getting an error in spring application: cvc-elt.1: Cannot find the declaration of element 'beans'

運行Spring應用程序時出現錯誤。 這是我的qtServlet-servlet xml文件。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:mvc="http://www.springframework.org/schema/mvc"
  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.2.4.RELEASE.xsd
  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.4.RELEASE.xsd
  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.4.RELEASE.xsd
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.4.RELEASE.xsd">

  <mvc:annotation-driven />
  <context:component-scan base-package="jp.co.vmt.qt" />

  <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />
  </bean>
  <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename" value="messages" />
  </bean>
</beans>

我收到此錯誤:

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 10 in XML document from ServletContext resource [/WEB-INF/qtServlet-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 10; columnNumber: 130; cvc-elt.1: Cannot find the declaration of element 'beans'.
    org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:399)

我已經在我的build.gradle文件中聲明了這一點

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }

    dependencies {
        classpath 'com.bmuschko:gradle-tomcat-plugin:2.0'

    }
}

apply plugin: 'eclipse'
eclipse {
    classpath {
        downloadSources=true
    }
}
apply plugin: 'java'
    dependencies {
        compile 'org.springframework:spring-beans:4.2.4.RELEASE'
        compile 'org.springframework:spring-context:4.2.4.RELEASE'
        compile 'org.springframework:spring-core:4.2.4.RELEASE'
//      compile 'org.springframework:spring:2.5.6'
        compile 'org.springframework:spring-web:4.2.4.RELEASE'
        compile 'org.springframework:spring-webmvc:4.2.4.RELEASE'
        compile 'org.hibernate:hibernate-core:4.3.6.Final'
//          compile 'javax.servlet:javax.servlet-api:3.1.0'
        compile 'org.slf4j:slf4j-simple:1.7.7'
        compile 'org.javassist:javassist:3.15.0-GA'
        compile 'mysql:mysql-connector-java:5.1.31'
        compile 'commons-dbcp:commons-dbcp:1.4'
        compile 'org.springframework.data:spring-data-jpa:1.9.2.RELEASE'
        compile 'org.springframework:spring-jdbc:4.2.4.RELEASE'
        compile 'org.springframework:spring-orm:4.2.4.RELEASE'
    }
apply plugin: 'war'
apply plugin: 'com.bmuschko.tomcat'


// JDK version source compatibility
sourceCompatibility = 1.7
// project version
version = '1.0'
// War file name
war.baseName = 'WebGradle'
// Web directory, this overrides the default value "webapp"
project.webAppDirName = 'WebContent'

repositories {
    mavenLocal()
    mavenCentral()
}

// Set source directory
sourceSets {
        main {
            java {
                srcDir 'src'
            }
        }
    }

// dependencies to run on tomcat, are mandatory for tomcat plugin
dependencies {
    def tomcatVersion = '7.0.57'
    tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
            "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}"
    tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
        exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
    }


}

// context where tomcat is deployed, by defautl localhost:8080/
tomcatRun.contextPath = '/'
tomcatRunWar.contextPath = '/'

我想我在我的qtServlet-servlet.xml以及build.gradle中都正確聲明了正確的依賴項和版本,但是我遇到了上述錯誤。 我已驗證jar文件在我的構建路徑以及tomcat的部署路徑中。 我不確定是什么引起了錯誤,因為類似的問題說xsds的版本與在依賴關系中聲明的版本不正確。 有什么幫助嗎? 謝謝。

從架構位置刪除版本信息。

嘗試這個:

xsi:schemaLocation="http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context.xsd"

暫無
暫無

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

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