Spring 3.0 - 无法找到XML模式名称空间上下文的Spring NamespaceHandler

时间:2015-04-05 10:43:16

标签: java xml spring maven spring-mvc

  

无法找到Spring   XML模式的NamespaceHandler   命名空间   [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]

这是我的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>   

在我的pom.xml中,我有:

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

项目树结构:
enter image description here 任何想法可能是什么原因?

3 个答案:

答案 0 :(得分:1)

通常,当我在eclipse下启动WebApp时会发生这种情况;我不知道为什么,似乎Eclipse找不到包含spring XSD架构的spring jar 通常我通过在WEB-INF / lib目录下添加spring jar来解决它(通过使用在pom.xml中声明的相同名称)

答案 1 :(得分:1)

如果您正在使用eclipse,请尝试以下步骤:

右键单击project-&gt; properties-&gt; Deployment Assembly-&gt; Java构建路径条目 - &gt; Maven依赖

这意味着在部署程序集中添加maven依赖项

答案 2 :(得分:0)

我在项目的POM中使用弹簧BOM(“物料清单”)取得了成功:

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

earliest version of spring-framework-bom in maven central repository is 3.2.6.RELEASE,您必须迁移到其他版本才能使用BOM。 BOM确保按版本一致地分辨工件。这也允许您从依赖项中删除所有<version>${spring.version}</version>

"versionless" xsd引用:

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