当前位置:   article > 正文

java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory_java.lang.noclassdeffounderror:org/apa

java.lang.noclassdeffounderror:org/apa

在学习spring的Setter注入时遇到了以下错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.<init>(DefaultSingletonBeanRegistry.java:82)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.<init>(FactoryBeanRegistrySupport.java:43)
    at org.springframework.beans.factory.support.AbstractBeanFactory.<init>(AbstractBeanFactory.java:176)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:159)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:170)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.<init>(DefaultListableBeanFactory.java:166)
    at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:78)
    at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:67)
    at yxd.spring.test.Manager.main(Manager.java:15)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)

    ... 9 more

以下是文件结构:

部分代码:

  1. public class Manager {
  2. @SuppressWarnings("deprecation")
  3. public static void main(String[] args) {
  4. Resource resource = new ClassPathResource("applicationContext.xml");
  5. BeanFactory factory = new XmlBeanFactory(resource);
  6. User user = (User)factory.getBean("user");
  7. System.out.println("用户姓名————" + user.getName());
  8. System.out.println("用户年龄————" + user.getAge());
  9. System.out.println("用户性别————" + user.getSex());
  10. }
  11. }
解决办法:

导入commons-logging.jar包。


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/279009
推荐阅读
相关标签
  

闽ICP备14008679号