我的博客:www.while0.com

我的博客:www.shishangguan.net

把spring 的lib下所有的jar包全部放入到buildpath下边,构建service.xml如下

 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
 5            http://www.springframework.org/schema/beans/spring-beans.xsd">
 6 
 7   <bean id="Student" class="money.spring.test.Student">
 8     <!-- collaborators and configuration for this bean go here -->
 9   </bean>
10 <!-- 
11   <bean id="StudentManager" class="money.spring.test.StudentManager">
12       <property name=""></property>
13   </bean>
14  -->
15   <!-- more bean definitions go here -->
16 
17 </beans>

Student.java的内容

 1 /**
 2  * 
 3  */
 4 package money.spring.test;
 5 
 6 /**
 7  * @author Administrator
 8  *
 9  */
10 public class Student {
11     private String name;
12     private int id;
13     
14     public String getName() {
15         return name;
16     }
17     public void setName(String name) {
18         this.name = name;
19     }
20     public int getId() {
21         return id;
22     }
23     public void setId(int id) {
24         this.id = id;
25     }
26     
27 }

单元测试StudentTest.java的内容

 1 package money.spring.test;
 2 
 3 import org.junit.Test;
 4 import org.springframework.context.ApplicationContext;
 5 import org.springframework.context.support.ClassPathXmlApplicationContext;
 6 
 7 public class StudentTest {
 8 
 9     @Test
10     public void testStudent() {
11         ApplicationContext context =
12                 new ClassPathXmlApplicationContext("service.xml");
13         //Student stu=context.getBean("Student",Student.class);//泛型构造方法,不需要手动转换
14         Student stu=(Student)context.getBean("Student");//返回object,需要手动转换
15     }
16 
17 }

这时出现如下错误提示

添加commons.logging.jar包后问题得到解决.

posted on 2013-03-20 15:06  money@money  阅读(271)  评论(0编辑  收藏  举报