- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Intellij,我的源类是 main.com.coding,我的资源文件是 main.com.testing。我将 spring.xml 文件放入资源文件中。
我的测试类位于 test.com.coding 中,我的测试资源文件位于 test.com.testing 中。
我尝试在我的主类中执行这样的代码:
public static void main(String[] args) throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext(args[0]);
在我的单元测试中,当我尝试测试该方法时,我尝试了这个,args[0] 是我的 spring 文件:
@Bài kiểm tra
public void testMain() throws Exception {
DataMain data = new DataMain();
String[] a = {"/config.context.xml","sample.text","output.text" };
data.main(a);
}
这是 config.context.xml 中的内容:
"http://www.springframework.org/dtd/spring-beans.dtd">
此外,我的 lib 路径中确实有 spirng.jar。我想知道他们找不到我的文件出了什么问题。我尝试在 main 方法中传递绝对路径,例如:
public static void main(String[] args) throws Exception {
String absPath = //absolute path of spring file for args[0]
ApplicationContext context = new ClassPathXmlApplicationContext(absPath );
这是我得到的错误:
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.springframework.context.support.AbstractApplicationContext.(AbstractApplicationContext.java:145)
at org.springframework.context.support.AbstractRefreshableApplicationContext.(AbstractRefreshableApplicationContext.java:84)
at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.(AbstractRefreshableConfigApplicationContext.java:59)
at org.springframework.context.support.AbstractXmlApplicationContext.(AbstractXmlApplicationContext.java:58)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:136)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
at com.main.DataMain.main(DataMain.java:46)
at com.test.TestDataMain.testMain(TestDataMain.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
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)
... 34 more
1 Câu trả lời
Thêm vàocommons-logging.jar
,您的错误就会得到解决。
我还建议您使用 maven,因为它在内部解决了所有依赖关系。
关于java - ClassPathXmlApplicationContext 出现 NoClassDefFoundError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31347747/
我通过听来学习 Java Spring Framework“Spring & Hibernate for Beginners”udemy 类(class)。我在尝试时挣扎导入org.springfra
我的主类的静态方法中有以下代码 - appContext = new ClassPathXmlApplicationContext(new String[] { "classp
我将 spring 与其他框架一起使用,并且我是序列化领域的新手。 问题是什么: 我需要序列化包含 org.eclipse.jetty.websocket.api.Session session (不
我正在使用 spring hibernate maven 项目。这里我得到了异常 dispatcher-servlet.xml 文件未找到。我应该如何添加路径。或者我应该在 .classpath 文件
我有这个代码... public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApp
“本地文件名”是指资源文件与类文件位于同一目录中。在下面的例子中,这是 JUnitRunner.class 文件。 Java 的 getResource()如果路径不是以 /' 开头,文件可以处理这个
我是 Spring 新手。我在将类路径作为 ClassPathXmlApplicationContext 的参数时遇到问题。我使用 Netbeans。我使用 ClassPathXmlApplicati
我正在使用 Intellij,我的源类是 main.com.coding,我的资源文件是 main.com.testing。我将 spring.xml 文件放入资源文件中。 我的测试类位于 test.
我正在尝试使用 Spring 3.2.0 创建连接,但出现 NullPointerException: ApplicationContext ctx = new ClassPathXmlApplica
我正在使用 spring-framework 和 hibernate 开发一个 Maven 项目。我有这两种方法: public void loadXml() throws IOException,
我们有一个不在 Web 容器中运行的应用程序,所以我正在尝试启动 Spring。在“main”函数中我们有这样的: public static void main(String[] args) thr
我尝试使用 PropertyPlaceholderConfigurer 加载属性文件中的一些变量,但它不起作用。互联网上的一些网站建议当 spring aop 不在类路径中时会出现问题,但我确保 ao
我的网络应用程序使用 iText 动态创建 PDF。 GlassFish 线程池用于在单独的线程中处理每个 PDF。 Spring 遍布整个应用程序以进行依赖注入(inject)。应用程序的所有模块都
尝试使用 Spring 。 xml文件在src下。我已经搜索过,但找不到问题所在。似乎找不到 xml 文件。 我收到以下错误: Exception in thread "main" java.
我阅读了几篇有关此问题的文章,但仍然不明白如何解决我的问题。我正在使用此源作为起点创建一个 Spring Web 服务: http://eggsylife.co.uk/2010/01/03/sprin
我使用Springframework的ClassPathXMLApplicationContext来初始化一些bean,如下所示: ctx = new ClassPathXMLApplicatio
这个问题已经有答案了: BeanFactory vs ApplicationContext (22 个回答) 已关闭 8 年前。 以下两条语句显然都是用于加载 xml 配置,但它们之间有什么区别? A
这个问题已经有答案了: What causes and what are the differences between NoClassDefFoundError and ClassNotFoundE
我的代码使用以下代码实例化一个 spring 实例: String filePath = "applicationContext.xml"; ApplicationContext context =
我在使用Springs框架时遇到了一个问题,导致服务器和数据库之间无法通信。 我创建的项目是Spring项目,然后重构为Maven。 在代码中的这一行:ClassPathXmlApplicationC
Tôi là một lập trình viên xuất sắc, rất giỏi!