7

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

SEVERE: Exception sending context initialized event to listener instance of
class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Unable to locate NamespaceHandler for namespace
[http://www.springframework.org/schema/context]
Offending resource: ServletContext resource [/WEB-INF/HelloWorld-service.xml]

This is my HelloWorld-service.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
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/util
    http://www.springframework.org/schema/util/spring-util-3.0.xsd"
     default-autowire="byName">

<context:component-scan base-package="com.test.service">
    <context:include-filter type="annotation"
        expression="org.springframework.stereotype.Service"/>
</context:component-scan>   

In my pom.xml I have:

<properties>
    <spring.version>3.0.5.RELEASE</spring.version>
</properties>
........
<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>${spring.version}</version>
    </dependency>

Project tree structure:
enter image description here Any ideas what could be the cause of this?

Kiran
  • 20,167
  • 11
  • 67
  • 99
  • Try removing the org.springframework spring-context ${spring.version} from pom.xml – Arpit Aggarwal Apr 06 '15 at 14:26
  • @Arpit. I tried bro. But No luck :( – Kiran Apr 06 '15 at 16:06
  • Do you have any other spring jars on classpath, i.e. in app server lib folder somewhere? – madteapot Apr 09 '15 at 16:25
  • I have spring jars (with different version) in maven folder (.m2). Will this be a problem? – Kiran Apr 09 '15 at 16:27
  • m2 folder shouldn't be problem but If its on your local machine I would suggest cleaning that and only resolving this project. Secondly do you package your jars in WEB-INF/lib folder or WEB-INF/lib/srping/[sub-folder]? – madteapot Apr 09 '15 at 16:29
  • Also please provide a tree structure of your war file that you are trying to deploy? – madteapot Apr 09 '15 at 16:30
  • @Setu: Please find attached project tree structure and all jars are in WEB-INF/lib folder. – Kiran Apr 09 '15 at 16:42
  • Sorry mate but I am not sure why this would be happening. Have you tried changing the app server you deployed on? Looks like you are using Spring tool suits and deploying to tomcat within. Get standalone tomcat and try to deploy on that and see what happens. – madteapot Apr 09 '15 at 19:21
  • @Unknown, can you provide the list of jars in lib folder and also the complete pom? I mostly think its because of dependency collision. – minion Apr 09 '15 at 19:43

3 Answers3

1

Ususally this happens when I started the WebApp under eclipse; I don't know why, it seems Eclipse can't find spring jars containing the spring XSD schemas Usually I solved it by adding spring jars under WEB-INF/lib directory (by using the same identical name declared in the pom.xml)

Angelo Immediata
  • 6,635
  • 4
  • 33
  • 65
1

If you are working with eclipse then try following steps:

Right click on project->properties->Deployment Assembly->Java build path entries-> Maven dependencies

That means add maven dependencies in your deployment assembly

Nimesh
  • 794
  • 3
  • 8
  • 18
0

I have had success using the spring BOM ("bill of materials") inside my project's POM:

<dependencyManagement>
    <dependencies>
      <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-framework-bom</artifactId>
         <version>3.2.6.RELEASE</version>
         <scope>import</scope>
         <type>pom</type>
      </dependency>
    </dependencies>
</dependencyManagement>

But the earliest version of spring-framework-bom in maven central repository is 3.2.6.RELEASE, and you would have to migrate to a different version to use a BOM. The BOM ensures consistent resolution of artifacts by version. This also allows you to remove all the <version>${spring.version}</version> from your dependencies.

And "versionless" xsd references:

xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context.xsd">
Community
  • 1
  • 1
Shane Voisard
  • 1,145
  • 8
  • 12