简体   繁体   English

在Spring应用程序中遇到错误:cvc-elt.1:找不到元素'beans'的声明

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

I am getting an error while running my Spring application. 运行Spring应用程序时出现错误。 Here is my qtServlet-servlet xml file. 这是我的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>

And I am getting this error: 我收到此错误:

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)

I have declared this in my build.gradle file 我已经在我的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 = '/'

I think I properly declared the correct dependencies and versions in both my qtServlet-servlet.xml as well as in build.gradle but I am getting the said error. 我想我在我的qtServlet-servlet.xml以及build.gradle中都正确声明了正确的依赖项和版本,但是我遇到了上述错误。 I have verified that the jar files are in my build path as well as the deployment path of tomcat. 我已验证jar文件在我的构建路径以及tomcat的部署路径中。 I'm not sure what's causing the error as similar questions say just incorrect versions of the xsds to the one declared in the depencencies. 我不确定是什么引起了错误,因为类似的问题说xsds的版本与在依赖关系中声明的版本不正确。 Any help? 有什么帮助吗? Thanks. 谢谢。

Remove the version info from the schema locations. 从架构位置删除版本信息。

Try this: 尝试这个:

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.

相关问题 使用spring获取错误消息“cvc-elt.1:找不到元素'beans'的声明。” - Getting error message with spring “cvc-elt.1: Cannot find the declaration of element 'beans'.” Spring:-cvc-elt.1:找不到元素“ beans”的声明 - Spring :- cvc-elt.1: Cannot find the declaration of element 'beans' 错误:cvc-elt.1:找不到元素“beans”的声明 - Error: cvc-elt.1: Cannot find the declaration of element 'beans' cvc-elt.1:找不到元素“beans”的声明 - cvc-elt.1: Cannot find the declaration of element 'beans' Spring cvc-elt.1:找不到元素&#39;beans&#39;的声明和类似的问题 - Spring cvc-elt.1: Cannot find the declaration of element 'beans' and similar problems org.xml.sax.SAXParseException; lineNumber:6; columnNumber:122; cvc-elt.1:找不到元素&#39;beans&#39;的声明 - org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 122; cvc-elt.1: Cannot find the declaration of element 'beans' cvc-elt.1:找不到元素“ countries”的声明 - cvc-elt.1: Cannot find the declaration of element 'countries' cvc-elt.1:找不到元素“更改集”的声明 - cvc-elt.1: Cannot find the declaration of element 'change-set' cvc-elt.1:找不到RootElement的元素声明 - cvc-elt.1: Cannot find the declaration of element for RootElement cvc-elt.1:找不到元素&#39;NewIssue&#39;的声明 - cvc-elt.1: Cannot find the declaration of element 'NewIssue'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM