菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
416
0

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

原创
05/13 14:22
阅读数 88902

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">  

 

 

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

发表评论

0/200
416 点赞
0 评论
收藏