[英]Getting error message with spring “cvc-elt.1: Cannot find the declaration of element '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.