【问题标题】:Spring-context configuration - namespaceSpring-context 配置 - 命名空间
【发布时间】:2014-12-08 17:12:04
【问题描述】:

我正在尝试使用 hibernate 和 JAX-WS 配置 spring 项目。

我在 servlet-context 文件中遇到问题 - 它向我显示它无法找到 spring-webmvc 的命名空间,但我确实在 pom.xml 中有它。

堆栈跟踪:

    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/mvc]
Offending resource: ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]

servlet-context 文件的开始:

<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    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" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:ws="http://jax-ws.dev.java.net/spring/core"
       xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        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
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd 
        http://jax-ws.dev.java.net/spring/core http://jax-ws.dev.java.net/spring/core.xsd
        http://jax-ws.dev.java.net/spring/servlet http://jax-ws.dev.java.net/spring/servlet.xsd">

pom.xml 中的重要元素(不是所有文件 - 我已经删除了我认为重要的内容):

 <properties>
        <org.springframework-version>4.0.3.RELEASE</org.springframework-version>
    </properties>

<dependencies>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework-version}</version>
            <exclusions>
                <!-- Exclude Commons Logging in favor of SLF4j -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        <dependency>
            <groupId>org.jvnet.jax-ws-commons.spring</groupId>
            <artifactId>jaxws-spring</artifactId>
            <version>1.8</version>
        </dependency>
    </dependencies>

任何帮助表示赞赏。

@编辑:

我意识到,当我从 pom 文件中删除 JAX-WS 依赖项时,一切似乎都可以正常工作(但后来我无法使用它......):

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

【问题讨论】:

    标签: spring maven spring-mvc jax-ws


    【解决方案1】:

    去掉http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd,你就好了

    更新

    如果您使用的是 mvc 命名空间,则不能确定将其删除,然后正确定义它

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        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.xsd
            http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc.xsd">
    
        <mvc:annotation-driven/>
    
    </beans>
    

    【讨论】:

    • 在这样做之后,注释驱动不起作用:来自 ServletContext 资源 [/WEB-INF/spring/appServlet/servlet-context.xml] 的 XML 文档中的第 17 行无效;嵌套异常是 org.xml.sax.SAXParseException;行号:17;列号:23; cvc-complex-type.2.4.c:匹配通配符是严格的,但找不到元素“注释驱动”的声明。
    • JAX-WS 依赖导致了这个错误——当我删除它时,一切正常,但是我不能使用这个 jar。
    【解决方案2】:

    您的项目中似乎没有 spring-mvc jar。如果您没有使用 spring mvc 相关功能,则删除 mvc 相关架构。 否则添加 spring mvc jar。

    【讨论】:

    • 我正在使用注释驱动 - 我猜它正在使用 spring-mvc。我在我的 pom spring-webmvc 和 Maven 依赖项中有我可以看到它已添加。
    猜你喜欢
    • 1970-01-01
    • 2019-05-07
    • 1970-01-01
    • 1970-01-01
    • 2016-01-17
    • 1970-01-01
    • 2017-01-12
    • 2015-03-01
    • 2014-10-11
    相关资源
    最近更新 更多