Java 利用 BeanUtils进行遇见的错误

错误提示:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.commons.beanutils.ConvertUtilsBean.(ConvertUtilsBean.java:157)
at org.apache.commons.beanutils.BeanUtilsBean.(BeanUtilsBean.java:117)
at org.apache.commons.beanutils.BeanUtilsBean$1.initialValue(BeanUtilsBean.java:68)
at org.apache.commons.beanutils.ContextClassLoaderLocal.get(ContextClassLoaderLocal.java:153)
at org.apache.commons.beanutils.BeanUtilsBean.getInstance(BeanUtilsBean.java:80)
at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:456)
at myMain.mainStu.main(mainStu.java:14)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory

at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more





package Model;



import java.util.Date;


public class Student {


 


    private String name;


    private int age;


    private Date birth;










    public String getName() {


           return name;


    }


    public void setName(String name) {


           this.name = name;


    }


    public int getAge() {


           return age;


    }


    public void setAge(int age) {


           this.age = age;


    }


    public Date getBirth() {


           return birth;


    }


    public void setBirth(Date birth) {


           this.birth = birth;


    }






}

=============================================》》》》


package myMain;


import java.lang.reflect.InvocationTargetException;


import org.apache.commons.beanutils.BeanUtils;


import Model.Student;


public class mainStu {


public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Student stu=new Student();
BeanUtils.setProperty(stu,"name","1234");


}


}




解决方法:

导入一个commons-logging.jar就可以解决


你可能感兴趣的:(Java 利用 BeanUtils进行遇见的错误)