gpt4 book ai didi

java - 运行 Spring Java 时出错

转载 作者:行者123 更新时间:2023-11-29 05:35:28 24 4
gpt4 key购买 nike

我是 java spring 的新手,想通过教程学习它。在本教程中,我收到以下错误:此错误也出现在另一个项目中...出了什么问题?

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.<init>(DefaultSingletonBeanRegistry.java:81)
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:165)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:78)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:67)
at org.semiz.DrawingApp.main(DrawingApp.java:12)
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

这里是类:

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;

public class DrawingApp {

public static void main(String[] args) {

BeanFactory factory = new XmlBeanFactory(new FileSystemResource(
"spring.xml"));

Triangle triangle = (Triangle) factory.getBean("triangle");
triangle.draw();
}
}

public class Triangle {

public void draw() {
System.out.println("Triangle draw");
}

}

最佳答案

看起来 XmlBeanFactory 具有日志记录依赖性。您需要包括 commons-logging jar 在你的类路径中。

关于java - 运行 Spring Java 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19644299/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com