4
votes

I'm trying to combine JUnit and Spring in a web project. Thanks to this question, I have succeeded in loading the spring config file into TestClass:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class TwitterServiceTest {
    @Resource
    IRepository repository;

But when the test runs, I got the following error:

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]

I guess that the problem might be that the library files are not in classpath. Currently I use Sysdeo Eclipse Tomcat plugin DevLoader to do the loading job (load jar file from M2_REPO to the classpath).

This project depends on many libraries. Is there any idea about how to fix this error? Any help would be greatly appreciated.

1
Why do you have the javaee namespace in your config file at all? It doesn't seem like a useful thing to have in a unit test. - skaffman
@skaffman: yes, you are right, I have put in the wrong file. - Hoàng Long

1 Answers

5
votes

I made a stupid mistake, which is using "web.xml" as spring configuration context file. SpringJUnit4ClassRunner try to parse it as the spring context file so it failed.

After including the right context file, the application works now.