英文:
JUnit Error: Failed to load ApplicationContext: Offending resource: class path resource
问题
我一直在尝试配置Junit中的应用程序上下文,就像这样:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = " ../application.xml ")
public class TestClass{
.....
}
当我运行JUnit时,我得到的错误是:
java.lang.IllegalStateException: 无法加载应用程序上下下文
Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: 配置问题:无法找到用于XML架构命名空间[http://java.sun.com/xml/ns/javaee]的Spring NamespaceHandler
Offending resource: class path resource [application.xml]
你有什么想法,可能出了什么问题?
英文:
I have been trying to configure application context in Junit like this:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "../application.xml")
public class TestClass{
.....
}
The error I get when I run the JUnit is:
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]
Any idea what might have wrong?
答案1
得分: 1
请检查您的application.xml
是否以以下内容开头:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
...
</beans>
英文:
check your application.xml
starts with this:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
...
</beans>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论