【发布时间】:2020-09-02 16:46:57
【问题描述】:
我一直在尝试像这样在 Junit 中配置应用程序上下文:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "../application.xml")
public class TestClass{
.....
}
我在运行 JUnit 时遇到的错误是:
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://java.sun.com/xml/ns/javaee]
Offending resource: class path resource [application.xml]
知道可能有什么问题吗?
【问题讨论】:
-
您不能使用相对文件路径格式。使用适当的基于类路径的路径(例如,将您的
application.xml放入src/main/resources并直接说locations = "application.xml")。 -
@chrylis-cautiouslyoptimistic- 我想这不是问题所在。它能够找到 application.xml 文件。但是当它阅读时,就有这个问题。
-
请春季版
-
@DineshDontha Spring 版本为 4.1.5
-
使用@ContextConfiguration("/application.xml")。如果不起作用,请发布您的项目结构
标签: java spring junit applicationcontext