I just announced the newSpring Security 5 modules (primarily focused on OAuth2) in the course:

>> CHECK OUT LEARN SPRING SECURITY

1. The Problem

This article will discuss one of the most common configuration problems in Spring – a namespace handler for one of the Spring namespaces is not found. Most of the time, this means one particular Spring jar is missing from the classpath – so let’s go over what these missing schemas might be, and what the missing dependency is for each one.

2. http://www.springframework.org/schema/security

The security namespace not being available is by far the most widely encountered problem in practice:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:beans="http://www.springframework.org/schema/beans"
    xsi:schemaLocation="
        http://www.springframework.org/schema/security 
        http://www.springframework.org/schema/security/spring-security-3.2.xsd
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-4.1.xsd">

</beans:beans>

Which leads to the following exception:

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: 
Configuration problem: 
Unable to locate Spring NamespaceHandler for XML schema namespace 
[http://www.springframework.org/schema/security]
Offending resource: class path resource [securityConfig.xml]

The solution is straightforward – the spring-security-config dependency is missing from the classpath of the project:

<dependency> 
   <groupId>org.springframework.security</groupId>
   <artifactId>spring-security-config</artifactId>
   <version>3.2.5.RELEASE</version>
</dependency>

This will put the correct namespace handler – in this case SecurityNamespaceHandler – on the classpath and ready to parse the elements in the security namespace.

The complete Maven configuration for a full Spring Security setup can be found in my previous Maven tutorial.

3. http://www.springframework.org/schema/aop

The same problem occurs when using the aop namespace without having the necessary aop spring library on the classpath:

<beans 
    xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-4.1.xsd">

</beans>

The exact exception:

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: 
Configuration problem: 
Unable to locate Spring NamespaceHandler for XML schema namespace 
[http://www.springframework.org/schema/aop]
Offending resource: ServletContext resource [/WEB-INF/webConfig.xml]

The solution is similar – the spring-aop jar needs to be added to the classpath of the project:

<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-aop</artifactId>
   <version>4.1.0.RELEASE</version>
</dependency>

In this case, the AopNamespaceHandler will be present on the classpath after adding the new dependency.

4. http://www.springframework.org/schema/tx

Using the transaction namespace – a small but very useful namespace for the configuration of the transactional semantics:

<beans 
    xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-4.1.xsd">

</beans>

will also result in an exception if the right jar is not on the classpath:

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: 
Configuration problem: 
Unable to locate Spring NamespaceHandler for XML schema namespace
[http://www.springframework.org/schema/tx]
Offending resource: class path resource [daoConfig.xml]

The missing dependency here is spring-tx:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-tx</artifactId>
    <version>4.1.0.RELEASE</version>
</dependency>

Now, the right NamspaceHandler – namely TxNamespaceHandler – will be present on the classpath allowing the declarative transaction management with both XML and annotations.

5. http://www.springframework.org/schema/mvc

Moving forward to the mvc namespace:

<beans 
    xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:tx="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">

</beans>

The missing dependency will lead to the following exception:

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: 
Configuration problem: 
Unable to locate Spring NamespaceHandler for XML schema namespace
[http://www.springframework.org/schema/mvc]
Offending resource: class path resource [webConfig.xml]

In this case, the missing dependency is spring-mvc:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>4.1.0.RELEASE</version>
</dependency>

Adding this to the pom.xml will add the MvcNamespaceHandler to the classpath – allowing the project to configure MVC semantics using the namespace.

6. Conclusion

Finally, if you’re using Eclipse to manage the web server and deploy – make sure that the Deployment Assembly section of the project is correctly configured – namely that the Maven dependencies actually are included on the classpath at deployment time.

This tutorial discussed the usual suspects for the “Unable to locate Spring NamespaceHandler for XML schema namespace” problem and provided solutions for each occurrence.

I just announced the new Spring Security 5 modules (primarily focused on OAuth2) in the course:

>> CHECK OUT LEARN SPRING SECURITY

Sort by:   newest | oldest | most voted
Anuja
Guest

Hi,

I get the same error but for spring-jms. The Spring-jms dependency is there is my configuration file but still not sure what is missing? Can you help?!!

Thanks!

Eugen Paraschiv
Guest

Hey Anuja, so – presumably you’re just missing the right dependency – similar to the other problems listed above. If you’ve already tried that and doesn’t solve the problem – let me know what the exact stacktrace is so that I can take a look. Cheers,
Eugen.

Anuja
Guest

Hi Eugen,

I actually had the dependency but the exact cause was that “Some of the spring jars contain meta info files with the same name.” Hence to avoid that some meta files are overridden, I used the maven-shade-plugin to merge them 🙂

Thanks for your reply though,
Anuja

Eugen Paraschiv
Guest

Sounds good. Cheers,
Eugen.

nikita shimpi
Guest

Hi,

I am facing this issue for dwr while deploying application on oracle 12 C.I am not using Maven.

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate NamespaceHandler for namespace [http://www.directwebremoting.org/schema/spring-dwr]
Offending resource: ServletContext resource [/WEB-INF/applicationContext.xml]

Please help.

Eugen Paraschiv
Guest

It simply looks like you’re missing a dependency – in your case, the dwr dependency. The first thing I’d try out is adding that in – Maven would make it easy to do so, but you can of course do it without Maven. Cheers,
Eugen.

Pavan
Guest

I am using ANT build and i have added all dependency ,its working on local weblogic 12c with windows platform but it is not working on Unix platform weblogic 12 c

Eugen Paraschiv
Guest

Hey Pavan – I’m afraid I don’t have a good way to replicate the problem but it sounds like it might be weblogic related. You should ask the question on StackOverflow as well as on weblogic related forums – you’ll probably get a better answer than my guess 🙂

Effie
Guest

Hi,
I’m facing an issue when adding the spring-security-config dependency.
I have a spring mvc project in eclipse (neon), using Spring 4.3.3. When I add the spring-security-config jar in the POM.xml (version 4.2.1), and run the project, I get “Server Tomcat v8.0 Server at localhost failed to start.”.
Any help on the matter would be greatly appreciated.
Thanks
Effie

Eugen Paraschiv
Guest

Hey Effie,
It’s hard to tell exactly what’s going on there just from your description. However, since you’re using Eclipse (and I assume m2e) – a simple way to diagnose these issues and make sure your Spring versions are in-sync with one another is – open the pom, go to the “Dependency Hierarchy” tab in the pom editor and just write “spring” in the filter. That’s going to help you immediately see what the issue is (likely with the versions).

Hope that helps. Cheers,
Eugen.

Effie
Guest

Thanks Eugen for your fast response.
I have the suspicion that the problem lies with a corrupt jar file (I tried the same setup/configuration on another computer and there was no problem).
Thanks again
Effie

wpDiscuz