關於spring項目報錯:找不到元素 'beans' 的聲明的解決辦法----絕對是頭文件的問題

請往下看:答案在下方:

現象:Tomcat啓動時,spring加載配置文件applicationContext.xml出錯,拋出nested exception is og.xml.sax.SAXParseException; lineNumber: 12; columnNumber: 47; cvc-elt.1: 找不到元素 'beans' 的聲明r的異常信息。

 

造成該異常原因:配置文件頭部配置的xsd版本信息不正確,造成解析時出錯。從本地jar包中找,如果找到則用本地jar包的進行校驗(可以在spring-beans.jar或spring-context.jar裏的META-INF下的spring-schemas文件中找到xsd文件位置的定義),如果沒有找到,它會嘗試從網絡中下載該文件然後校驗,如果系統斷網或下載不下來,則會拋出上述異常.以下可以查看你的jar包裏是否有你的版本,如果沒有也是找不到的,就會有異常

第一步:

第二步:

 

解決辦法:

一定要注意如果spring版本是3._的話 ,,頭文件一定要用3._的版本,是4.幾 的就用4.幾的版本,,絕對不能越級訪問,頭文件斑斑低或者高都會報錯顯示 找不到   元素beans的聲明

我用的是 “   springMVC  --4.3.19   ” 的      以下是我的解決後的頭文件,可以參考:

<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章