Cannot find the declaration of element 'beans'异常的解决办法

在网上搜了一下,发现有很多人提供了解决的办法,但我一一试过,最终都不行。
解决方案列表如下:
1、[分享]Spring启动异常: cvc-elt.1: Cannot find the declaration of element 'beans'
2、spring从sun jdk到IBMjdk

这两篇文章中都提供了各自的解决方法,但为何在我的应用中就是不行了?
其实不是不行,而是需要根据Spring的版本不同,进行不同的处理,刚好我用的是Spring2.5,所以解决起来需要另一种方法,即配置文件XML的头部的声明应该为:
<? xml version="1.0" encoding="UTF-8" ?>

<!--
  - Application context definition for JPetStore's business layer.
  - Contains bean references to the transaction manager and to the DAOs in
  - dataAccessContext-local/jta.xml (see web.xml's "contextConfigLocation").
  
-->
< 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:tx
="http://www.springframework.org/schema/tx"
         xsi:schemaLocation
="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
>

这段声明,是来自Spring2.5包中自带的Sample目录中的一些例子的代码中,当我把我的XML的头部改成这样以后,果然可以顺利启动。

你可能感兴趣的:(Cannot find the declaration of element 'beans'异常的解决办法)