Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么junit给我一个加载ApplicationContext失败的错误_Java_Spring_Junit - Fatal编程技术网

Java 为什么junit给我一个加载ApplicationContext失败的错误

Java 为什么junit给我一个加载ApplicationContext失败的错误,java,spring,junit,Java,Spring,Junit,我正试图在eclipse中运行我的第一个junit类。当我右键单击新类并选择RunasJUnit时,会出现加载applicationcontext失败的错误。spring-servlet.xml的直接路径是正确的 代码如下: import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframe

我正试图在eclipse中运行我的第一个junit类。当我右键单击新类并选择RunasJUnit时,会出现加载applicationcontext失败的错误。spring-servlet.xml的直接路径是正确的

代码如下:

import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"file:C:/MyProject/WEB-INF/spring-servlet.xml" 
}) 
public class MyUnitTest {
@Autowired
private ApplicationContext applicationContext;

@Before
public void setUp() {
}

@Test
public void testFunctionality() throws Exception {
    assertTrue(true);
}
}
错误-

Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'aop:scoped-proxy'.
通往 spring-servlet.xml是正确的

不,不是。如果是的话,朱尼特早就找到了

我认为应该是这样的:

@ContextConfiguration(locations={"file:///C:/MyProject/WEB-INF/spring-servlet.xml"

更新:

您发布的错误消息说您确实读取了上下文XML,但出现了一个错误

我发现把我收到的任何错误信息粘贴到谷歌上都很有帮助。当我对你这样做的时候,它给了我这个:

检查丢失的罐子