181

Any ideas what could be the cause of this?

Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security]

org.springframework.web.context.ContextLoader initWebApplicationContext: Context initialization failed
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: ServletContext resource [/WEB-INF/applicationContext.xml]

This is my applicationContext.xml:

<?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"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security-3.0.xsd">
...
</beans:beans>

In my pom.xml I have:

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-core</artifactId>      
    <version>3.0.1.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-openid</artifactId>
    <version>3.0.1.RELEASE</version>
</dependency>
Taylor Leese
  • 51,004
  • 28
  • 112
  • 141

15 Answers15

287

I needed to add an additional Maven dependency:

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>3.0.1.RELEASE</version>
    </dependency>
Taylor Leese
  • 51,004
  • 28
  • 112
  • 141
  • 3
    +1 For solving my problem. More info can be found on the restructuring of the spring security 3.0 codebase at: http://blog.springsource.com/2009/06/03/spring-security-300m1-released/ – Rydell May 07 '10 at 14:11
  • Nice link. I could have used that a few months ago as well. – Taylor Leese May 07 '10 at 16:00
  • 12
    Bacon saved by SO yet again! – Andrew Swan Oct 15 '10 at 06:25
  • Similar solution holds when attempting to use only the `spring-security-cas` jar. – Ryan Ransford Jan 15 '13 at 14:22
  • I do recommend this [link](http://www.baeldung.com/unable-to-locate-spring-namespacehandler-for-xml-schema-namespace) for those with `Unable to locate Spring NamespaceHandler for XML schema namespace [xxxxx]` problems. I had a [similar issue](http://stackoverflow.com/questions/36690949/error-unable-to-locate-spring-namespacehandler-for-xml-schema-namespace/36695608#36695608) in the past, and that helped me a lot! – Cotta May 17 '16 at 11:47
18

I had the same error message while trying to deploy the application. In Spring, the security configuration xml can be a different one from applicationContext.xml, usually applicationContext-security.xml inside WEB-INF folder. The changes to be applied are for web.xml

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/applicationContext.xml
        /WEB-INF/applicationContext-security.xml
    </param-value>
</context-param>

And the applicationContext.xml would look like:

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

    <http auto-config='true'>
        <intercept-url pattern="/login.jsp" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
        <intercept-url pattern="/**" access="ROLE_USER" />
        <form-login login-page='login.jsp'/>
    </http>

</beans:beans>

Even after you make these changes, the namespace error will exist. To get rid of this, add the following jar files to the WEB-INF/lib and then to the library:

  • spring-security-acl-3.1.0.M2.jar
  • spring-security-config-3.1.0.M2.jar
  • spring-security-core-3.1.0.M2.jar
  • spring-security-taglibs-3.1.0.M2.jar
  • spring-security-web-3.1.0.M2.jar
James Jithin
  • 10,183
  • 5
  • 36
  • 51
  • You pretty much have to use Maven to get Spring going. And when you reluctantly do just that, it still doesn't work! Somebody, somewhere is laughing hard... This answer helped reduce my frustration a little bit. – Arne Evertsson Feb 08 '13 at 17:39
12

I struggled with this for a while and none of these answers helped. Thanks to the comment from user64141 I realised that there was a problem with the spring.handlers files.

I am using the Shade plugin for Maven to generate a fat jar, and all the spring.handlers (and spring.schemas) files were being overwritten by each Spring dependency.

The Maven site covers this exact problem and how to solve it by appending the files together instead:

http://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#AppendingTransformer

Patrick Herrera
  • 3,120
  • 26
  • 21
8

I used spring-security-config jar it resolved the problem for me

abhiram
  • 81
  • 1
  • 1
6

The solution is definitely "spring-security-config" not in your WEB-INF/lib.

For my project in Eclipse using Maven, it turned out not all of the maven dependencies were being copied to WEB-INF/lib. Looking at Project -> Properties -> Deployment Assembly, only some of the jars were being copied.

To fix this, I clicked "Add", then "Java Build Path Entires" and finally "Maven Dependencies".

I have been searching SO and the web for the last hour looking for this, so hopefully this helps someone else.

Peter Sankauskas
  • 2,882
  • 4
  • 27
  • 28
3

A nice list of Maven Dependencies exists at : Spring Site The major artifacts needed are:

  1. spring-security-core
  2. Spring-security-web
  3. spring-security-config
George Papatheodorou
  • 1,539
  • 19
  • 23
3

@James Jithin - such exception can appear also when you have two different versions of beans and security schema in xsi:schemaLocation. It's the case in the snippet you have pasted:

xsi:schemaLocation="http://www.springframework.org/schema/beans   
 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd   
 http://www.springframework.org/schema/security  
 http://www.springframework.org/schema/security/spring-security-3.1.xsd"

In my case changing them both to 3.1 solved the problem

ForestierSimon
  • 415
  • 4
  • 8
  • I've just managed to get it to work with: `http://www.springframework.org/schema/beans/spring-beans-3.1.xsd` `http://www.springframework.org/schema/security/spring-security-3.2.xsd` In my case I had 'spring-security-config' jar missing. – Ithar Jan 05 '15 at 16:47
  • Agreed with this comment. Had my issue due to this cause. – DolphinJava May 06 '15 at 18:06
2

What I did:

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

and

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">

works perfectlly. More Baeldung

Xelian
  • 16,680
  • 25
  • 99
  • 152
0

If you already have all dependencies in your pom, try:
1. Remove all downloaded jars form your maven repository folder for 'org->springframework'
2. Make a maven clean build.

arviarya
  • 650
  • 9
  • 9
0

I have encountered the very similar problem today. For some reason IntelliJ IDEA haven't included Spring Security jar files while deploying the application. I think I should agree with the majority of posters here.

shapiy
  • 1,117
  • 12
  • 14
0

I got this error while deploying to Virgo. The solution was to add this to my bundle imports:

org.springframework.transaction.config;version="[3.1,3.2)",

I noticed in the Spring jars under META-INF there is a spring.schemas and a spring.handlers section, and the class that they point to (in this case org.springframework.transaction.config.TxNamespaceHandler) must be imported.

user64141
  • 5,141
  • 4
  • 37
  • 34
0

I found this solution:

http://www.javacreed.com/unable-to-locate-spring-namespacehandler-for-xml-schema-namespace-httpwww-springframework-orgschemamvc/

Include this jar in your project

0

Had the same problem a few minutes ago, I was missing the 'Maven depencendies' library in my Deployment Assembly. I added it through the section 'Web Deployment Assembly' in Eclipse

LucaEffe
  • 103
  • 1
  • 8
0

if adding dependencies haven`t solved your problem, create WAR archive again. In my case, I used obsolete WAR file without security-web and security-conf jars

0

Add the following dependency in your pom.xml file and if you are using IntelliJ then add the same jars to WEB-INF->lib folder.... path is Project Structure -> Atrifacts -> Select jar from Available Elements pane and double click. It will add to respective folder

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-config</artifactId>
    <version>3.0.1.RELEASE</version>
</dependency>
Sia
  • 47
  • 1
  • 1
  • 9