LostMohican
LostMohican

Reputation: 3144

maven and spring app deploy error : Unable to locate NamespaceHandler for namespace [http://www.springframework.org/schema/context]

I have a multi module maven app, with two children modules. One module is for web services and the other one will be the simulator that uses these services.

I have a strange problem, when i want to deploy my application, which i started yesterday, I have the following error from Tomcat7:

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/application-context.xml]

And my application-context.xmls top section looks like this :

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

    <context:component-scan base-package="com.company">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

It says that it cannot find a namespace handler for spring context. But I have that dependency in my parent pom.xml like this :

 <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>3.1.2.RELEASE</version>
    </dependency>

I can also see that the web app in Tomcat has also the spring-context jar in the lib folder of the application. I have been googling around for two hours, so any help will be appreciated.

Thanks

Upvotes: 2

Views: 1501

Answers (2)

LostMohican
LostMohican

Reputation: 3144

i found the error on my pom.xml, i am writing it down for myself for in future i might encounter again : )

i had my pom.xml like this

       <dependency>
            <groupId>org.jvnet.jax-ws-commons.spring</groupId>
            <artifactId>jaxws-spring</artifactId>
            <version>1.8</version>
        </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${springFrameworkVersion}</version>
    </dependency>

So, jaxws-spring has already a dependency to Spring 2.0. This makes maven to put the jar spring-2.0 to the war also. So I was having library collision of some sort.

When I put an exclusion like below, problem solved:

<dependency>
            <groupId>org.jvnet.jax-ws-commons.spring</groupId>
            <artifactId>jaxws-spring</artifactId>
            <version>1.8</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

Upvotes: 0

user944849
user944849

Reputation: 14951

Take a look at this part of the maven-shade-plugin docs, which talk explicitly about Spring namespace handlers.

Upvotes: 1

Related Questions