Spring链接:
http://s3.amazonaws.com/dist.springframework.org/release/SPR/spring-framework-3.0.5.RELEASE.zip
下载完毕后,解压缩到合适的目录,推荐放到eclipse目录的plugin中。
导入有两种方法,推荐方法一。
方法一:
Preferences->Java->Build Path->User Libraries中
- New一个User Library,命名为spring
- Add JARs,将之前解压出的JAR包添加到spring中
- 点击OK,确定
- 左键项目名->Properties
Java Build Path->Add Library->User Library->Next选中之前添加好的User Library,Finish
于是Spring库导入成功
方法二:
直接将Spring库文件导入到项目的Java Build Path属性中。
将Spring库导入之后运行Spring测试程序发现报错:
Exception in thread "main" java.lang.NoClassDefFoundError:org/apache/commons/logging/LogFactory atorg.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:160) atorg.springframework.context.support.AbstractRefreshableApplicationContext.<init>(AbstractRefreshableApplicationContext.java:89) atorg.springframework.context.support.AbstractRefreshableConfigApplicationContext.<init>(AbstractRefreshableConfigApplicationContext.java:59) atorg.springframework.context.support.AbstractXmlApplicationContext.<init>(AbstractXmlApplicationContext.java:61) atorg.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:137) atorg.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84) aterictest.EricTest.main(EricTest.java:8) |
发现是缺少Spring依赖的commons-logging库
commons-logging库:http://commons.apache.org/logging/download_logging.cgi
用同样的方法导入commons-logging之后程序即可正确运行。
撒花!