通配符的匹配很全面, 但無法找到元素 'context:component-scan' 的聲明


一. 異常描述
在配置SpringMVC的時候,spring.xml文件中配置了 <context:component-scan/>,
結果提示如下異常:

Caused by: org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 71; cvc-complex-type.2.4.c: 通配符的匹配很全面, 但無法找到元素 'context:component-scan' 的聲明
 

 

 

二. 錯誤原因
一般是因為這個spring.xml文件中的命名空間依賴型沒有聲明完整,一些必要的依賴項沒有添加進來,尤其是利用IDE工具自動生成的xml文件,很多時候依賴項都不完整!!!

 

 

 

三. 解決辦法
復制完整的命名空間.

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

 

原文鏈接:https://blog.csdn.net/syc000666/article/details/95052629


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM