码迷,mamicode.com
首页 > 编程语言 > 详细

(Spring加载xml时)org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.

时间:2016-05-01 01:02:11      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:

ApplicationContext ctx = new ClassPathXmlApplicationContext("test.xml");报错

在启动Spring时,报以下错误,如图:

技术分享

原因是在xml中spring的xsd的版本配置的不一致,我使用的是spring-2.5.6,但配置文件中配的是3.0。改成如下即可:

[xhtml] view plain copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">  

 

 

另外,配置时,要注意配置文件的编码;否则当编译时,输出的编码和你的配置文件的编码不一致时,会产生文件乱码。

(Spring加载xml时)org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.

标签:

原文地址:http://www.cnblogs.com/beijingstruggle/p/5449803.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!