开发者

Why is junit giving me a failed to load ApplicationContext error

开发者 https://www.devze.com 2023-03-17 01:46 出处:网络
I am trying to run my first junit class in eclipse.When I right click on the new class and select run as junit it gives me a failed to load applicationcontext error.The direct path to the spring-servl

I am trying to run my first junit class in eclipse. When I right click on the new class and select run as junit it gives me a failed to load applicationcontext error. The direct path to the spring-servlet.xml is correct.

Here's the code:

import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.fa开发者_JAVA技巧ctory.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);
}
}

error -

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'.


The direct path to the spring-servlet.xml is correct.

No, it's not. If it was, JUnit would have found it.

I think it should look like this:

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

http://en.wikipedia.org/wiki/File_URI_scheme

UPDATE:

The error message you posted says you did read the context XML, but there's an error.

I find that it's helpful to paste any error message I get into Google. When I did that with yours, it sent me this:

http://forum.springsource.org/showthread.php?35417-The-matching-wildcard-is-strict-but-no-declaration-can-be-foun...-aop-scoped-proxy

Check for missing JARs.

0

精彩评论

暂无评论...
验证码 换一张
取 消