2

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.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);
}
}

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

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.