Wednesday, July 14, 2010

Tip: Provide the Spring Security NamespaceHandler Explicitly

If you're working with Spring Security, you might start your pom with an entry like so:
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-web</artifactId>
    <version>3.0.0.RELEASE</version>
</dependency>
This will bring in the spring-web, spring-security-core and commons-logging artifacts, and I would not fault you for thinking you're good to go. You're possibly following this tutorial or another among the many out there, and are providing a Spring config that references the http://www.springframework.org/schema/security namespace - and, at least for me, here's where things did not go as expected. At runtime, the error message I received was this:

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

After a fair amount of Google'ing and Stack-Overflow'ing, I found the problem - and I reproduce it here to save myself (and hopefully you) the headache next time around: there is a dependency missing that looks like this:
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-config</artifactId>
    <version>3.0.0.RELEASE</version>
 </dependency>

Now you should be good to go.

5 comments:

  1. I really hope this helps someone in the future. I had the same issue, added spring-security-config in my pom, but still had the same issue. I use the m2e plugin in eclipse. I don't know the details, but I had to delete my .m2/repository folder and have eclipse regenerate it in order to see any difference.

    ReplyDelete
  2. You are genius! Thanks a lot! )))

    ReplyDelete
  3. Well, "genius" is a bit over the top. But thank you, and I'm glad it helped.

    ReplyDelete