JUnit错误:无法加载应用上下文:有问题的资源:类路径资源

huangapple go评论68阅读模式
英文:

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:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd&quot;&gt;
	
...

&lt;/beans&gt;

huangapple
  • 本文由 发表于 2020年9月3日 00:46:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/63710034.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定