Configuration problems: Unable to locate Spring Na

2019-02-23 20:13发布

问题:

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:

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.