Sping_0200_IOC_Introduction(Spring2.5环境搭建)
首先,通过Spring Framework -Reference Documentation(E:\source\doc\spring-framework-2.5.6-with-dependencies\spring-framework-2.5.6\docs\reference\html_single\index.html)引入Spring2.5的xml配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="..." class="...">
<!-- collaborators and configuration for this bean go here -->
</bean>
<bean id="..." class="...">
<!-- collaborators and configuration for this bean go here -->
</bean>
<!-- more bean definitions go here -->
</beans>
其次,向项目中添加spring对应的jar包
第一:Window-->Preference-->Java-->Build Path-->new(new一个userLib),然后点击Add Jars导入Spring.jar文件。
第二:选择项目右键,Build Path-->add Libraries-->User Library-->选择刚建的userLib,这样就将Spring.jar添加到项目中了。
最后,进行Junit测试
Failure Trace
java.lang.NoClassDefFoundError:org/apache/commons/logging/LogFactory
原因:缺少日志jar包, 添加commons-logging.jar包
测试方法:
public class UserServiceTest {
@Test
public void testAdd()throws Exception {
ApplicationContext applicationContext=new ClassPathXmlApplicationContext("beans.xml");
UserService service=(UserService)applicationContext.getBean("userService");
User u=new User();
service.add(u);
}
}
@longkouzhonglu.tianhequ.guangzhou 2014-10-10 10:57