您的位置:首页 > 编程语言 > Java开发

spring测试中发现的问题

2013-03-20 15:06 239 查看
我的博客:www.while0.com

把spring 的lib下所有的jar包全部放入到buildpath下边,构建service.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.xsd"> 
<bean id="Student" class="money.spring.test.Student">
<!-- collaborators and configuration for this bean go here -->
</bean>
<!--
<bean id="StudentManager" class="money.spring.test.StudentManager">
<property name=""></property>
</bean>
-->
<!-- more bean definitions go here -->

</beans>


Student.java的内容

/**
*
*/
package money.spring.test;

/**
* @author Administrator
*
*/
public class Student {
private String name;
private int id;

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}

}


单元测试StudentTest.java的内容

package money.spring.test;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class StudentTest {

@Test
public void testStudent() {
ApplicationContext context =
new ClassPathXmlApplicationContext("service.xml");
//Student stu=context.getBean("Student",Student.class);//泛型构造方法,不需要手动转换
Student stu=(Student)context.getBean("Student");//返回object,需要手动转换
}

}


这时出现如下错误提示



添加commons.logging.jar包后问题得到解决.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: