最近学习Spring,搭建环境花费了点时间,主要是错误比较多:
总结了一下:
1.要运行简单的Spring程序,需要导入一下几个jar包:
commons-logging-1.3.jar
log4j-1.2.8.jar
spring-2.5.6.jar
这些Jar包可以到下面的网站下载:
http://jarfiles.pandaidea.com/commons-logging.html
2.导入以上jar包后,可以解决不少错误,此时,运行程序,抛出一下异常:
nested exception is og.xml.sax.SAXParseException; lineNumber: 12; columnNumber: 47; cvc-elt.1: 找不到元素 'beans' 的声明
网上找了下,原因是引用的Spring jar包版本不同导致的,
解决办法:
两个不同版本的spring配置文件的头格式如下两种,如果你已经是其中一种,则改成另一种即可。
第一种:
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
......
第二种:
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
http://zhaowenbinmail.blog.163.com/blog/static/3908086201143134428201/