【问题标题】:Spring Integration - Spring example config namespace issueSpring Integration - Spring 示例配置命名空间问题
【发布时间】:2015-08-24 18:44:05
【问题描述】:

问题:在我的 spring 配置文件中获取元素的命名空间错误。

“无法找到架构名称空间'http://www.springframework.org/schema/integration/ws'的元素“int-ws:hyeader-enricher”的Spring NamespaceHandler

描述: 尝试使用 maven 在一个简单的 spring sts spring 项目中从 spring 网站创建 Spring Integration 示例项目。

我没有在示例目录中找到这个项目供我比较。

http://projects.spring.io/spring-integration/

Spring Bean 配置文件

<?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:context="http://www.springframework.org/schema/context"
    xmlns:int="http://www.springframework.org/schema/integration"
    xmlns:int-http="http://www.springframework.org/schema/integration/http"
    xmlns:int-ws="http://www.springframework.org/schema/integration/ws"
    xmlns:int-xml="http://www.springframework.org/schema/integration/xml"
    xsi:schemaLocation="http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http.xsd
        http://www.springframework.org/schema/integration/ws http://www.springframework.org/schema/integration/ws/spring-integration-ws.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.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/integration/xml http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd">


<!-- Simple Service -->

<int:gateway id="simpleGateway"
    service-interface="foo.TempConverter"
    default-request-channel="simpleExpression" />

<int:service-activator id="expressionConverter"
    input-channel="simpleExpression"
    expression="(payload - 32) / 9 * 5"/>

<!-- Web Service -->

<int:gateway id="wsGateway" service-interface="foo.TempConverter"
    default-request-channel="viaWebService" />

<int:chain id="wsChain" input-channel="viaWebService">
    <int:transformer
       expression="'&lt;FahrenheitToCelsius xmlns=''http://www.w3schools.com/webservices/''&gt;&lt;Fahrenheit&gt;XXX&lt;/Fahrenheit&gt;&lt;/FahrenheitToCelsius&gt;'.replace('XXX', payload.toString())" />
    <int-ws:header-enricher>
        <int-ws:soap-action value="http://www.w3schools.com/webservices/FahrenheitToCelsius"/>
    </int-ws:header-enricher>
    <int-ws:outbound-gateway
        uri="http://www.w3schools.com/webservices/tempconvert.asmx"/>
    <int-xml:xpath-transformer
        xpath-expression="/*[local-name()='FahrenheitToCelsiusResponse']/*[local-name()='FahrenheitToCelsiusResult']"/>
</int:chain>

</beans>

更新 - 解决方案 我必须添加该网站上未列出的以下依赖项。我将此添加到 POM 文件中。

<dependency>
    <groupId>org.springframework.integration</groupId>
    <artifactId>spring-integration-ws</artifactId>
    <version>4.1.6.RELEASE</version>

</dependency>
<dependency>
    <groupId>org.springframework.integration</groupId>
    <artifactId>spring-integration-xml</artifactId>
    <version>4.1.6.RELEASE</version>
</dependency>

【问题讨论】:

    标签: spring spring-integration


    【解决方案1】:

    Spring XML 配置命名空间在运行时需要命名空间处理程序(META-INF/spring.handlers 类路径资源,通常在类路径上的 JAR 中,指定处理程序类)。

    Spring 在运行时提供此消息的原因是尚未为该 XML 元素注册命名空间处理程序。最可能的原因是 spring-integration-ws.jar(或者可能是必需的依赖项)在运行时不在类路径上。

    【讨论】:

    • 在验证 spring 配置 xml 期间出现此消息。不是运行时间。我将检查 spring 集成示例目录中的 spring.handlers 文件。然而,在 STS 中创建一个新的 spring 项目似乎很奇怪,不会创建必要的文件。我也会尝试在 gradle vs maven 中做这个项目。所以就像很多工作只是为了让 1 个示例项目正常工作。
    • STS 可能正在针对项目依赖项进行验证。您不必自己创建 spring.handlers 文件:只需将正确的 JAR 放在类路径上。检查您的 pom.xml 文件是否有 spring-integration-ws 作为依赖项(如果您使用的是 Maven)。
    • 根据 Spring IO Integration 网站上的示例,我只有 spring-integration-core 对 4.1.6 版本的依赖。我会尝试上传它的截图。
    • 好吧,看看 GitHub 中的代码,http://www.springframework.org/schema/integration/ws 命名空间需要 spring-integration-ws 作为依赖项。
    • 你说得对。出于某种原因,他们把它留在了那里的网站上。不知道为什么 Spring 会这样做。我必须添加以解决验证冲突。能把项目的链接发到github吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多