zoukankan      html  css  js  c++  java
  • spring测试中发现的问题

    我的博客: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包后问题得到解决.

  • 相关阅读:
    玩机分享之群晖利用反代域名访问
    Clipboard.SetText()卡住问题
    KB4040973 KB3178034 补丁导致wpf无法启动异常
    WPF 启动缓慢问题
    Jetbrains系列产品2019.2.3最新激活方法
    .net 4.0 以下HttpWebRequest Header 修改hosts方法
    Crypto++ 无法解析的外部符号 CryptoPP::AssignIntToInteger
    关于WDK开发内核签名之WHQL签名认证流程简介
    ico制作工具
    VUE监听滚动条事件
  • 原文地址:https://www.cnblogs.com/yamadie/p/2971203.html
Copyright © 2011-2022 走看看