【问题标题】:spring-integration-mqtt configuration issue (no declaration for element found)spring-integration-mqtt 配置问题(未找到元素声明)
【发布时间】:2014-03-20 15:21:59
【问题描述】:

我想使用 Spring Integration 4.0.0M3 的 MQTT 支持,到目前为止,我已经配置了 application-context 并定义了一些集成。它在我的 IDE 中都是绿色的,所有必需的依赖项都在这里。如果我现在尝试启动我的应用程序,我会在启动期间收到以下异常:

/mqtt-application-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 24; columnNumber: 67; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'int-mqtt:message-driven-channel-adapter'.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:266)
... 62 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 24; columnNumber: 67; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'int-mqtt:message-driven-channel-adapter'.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)

我的spring-integration相关上下文配置:

<?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:int="http://www.springframework.org/schema/integration"
   xmlns:int-mqtt="http://www.springframework.org/schema/integration/mqtt"
   xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
    http://www.springframework.org/schema/integration/mqtt http://www.springframework.org/schema/integration/mqtt/spring-integration-mqtt.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    ">
<import resource="customer-propertyPlaceholder-config.xml" />
<bean id="clientFactory"
      class="org.springframework.integration.mqtt.core.DefaultMqttPahoClientFactory">
    <property name="userName" value="${mqtt.username}"/>
    <property name="password" value="${mqtt.password}"/>
</bean>
<int-mqtt:message-driven-channel-adapter id="twoTopicsAdapter"
                                         client-id="${mqtt.clientId}"
                                         url="${mqtt.url}"
                                         topics="bar, baz"
                                         channel="startCase"/>
<int:service-activator id="startCase" input-channel="startCaseAdapter" ref="mqttCaseService" method="startCase" />
<bean id="mqttCaseService" class="foo.bar.mqtt.MqttCaseService" />

我还尝试通过类路径指定架构位置:

http://www.springframework.org/schema/integration/mqtt classpath:/org/springframework/integration/mqtt/config/xml/spring-integration-mqtt-4.0.xsd

但这并不能解决我的问题,即使提到的元素也在类路径的架构中声明:

<xsd:element name="message-driven-channel-adapter">
    <xsd:annotation>
        <xsd:documentation>
            The definition for the Spring Integration MqttAdapter
            Inbound Channel Adapter.
        </xsd:documentation>
    </xsd:annotation>
    <xsd:complexType>
        <xsd:attributeGroup ref="coreMqttComponentAttributes"/>
        <xsd:attribute name="channel" type="xsd:string">
            <xsd:annotation>
                <xsd:appinfo>
                    <tool:annotation kind="ref">
                        <tool:expected-type type="org.springframework.integration.core.MessageChannel" />
                    </tool:annotation>
                </xsd:appinfo>
            </xsd:annotation>
        </xsd:attribute>
        <xsd:attribute name="topics">
            <xsd:annotation>
                <xsd:documentation>
                    Specifies one or more (comma-delimited) topics on which to listen for messages.
                </xsd:documentation>
            </xsd:annotation>
        </xsd:attribute>
        <xsd:attribute name="send-timeout" type="xsd:string">
            <xsd:annotation>
                <xsd:documentation><![CDATA[
                    Allows you to specify how long this inbound-channel-adapter
                    will wait for the message (containing the retrieved entities)
                    to be sent successfully to the message channel, before throwing
                    an exception.

                    Keep in mind that when sending to a DirectChannel, the
                    invocation will occur in the sender's thread so the failing
                    of the send operation may be caused by other components
                    further downstream. By default the Inbound Channel Adapter
                    will wait indefinitely. The value is specified in milliseconds.
                ]]>
                </xsd:documentation>
            </xsd:annotation>
        </xsd:attribute>
    </xsd:complexType>
</xsd:element>

有没有人暗示我在这里做错了什么?

亲切的问候, 迈克尔

【问题讨论】:

  • 看起来您的 IDE 从一个地方使用 XSD,但是当您运行应用程序时,它使用不同的地方作为 CLASSPATH。
  • 您确定spring-integration-mqtt.4.0.0.M3.jar 在运行时类路径中吗?使用classpath: 将不起作用。 Spring 通过查看 jar 中的 META-INF/spring.schemas 来找到架构。
  • @GaryRussell 我在我的 Gradle 配置中使用 // Spring Integration / MQTT compile ('org.springframework.integration:spring-integration-mqtt:4.0.0.M3')。
  • 如果只有一行,则将其注释掉。
  • 仅供参考,我刚刚创建了一个全新的独立 gradle 项目,它对我来说都按预期工作。

标签: spring spring-integration mqtt


【解决方案1】:

好的,我想我设法避免了这种情况。 spring-integration-core 存在版本冲突。

【讨论】:

    猜你喜欢
    • 2012-09-13
    • 1970-01-01
    • 2016-04-21
    • 1970-01-01
    • 1970-01-01
    • 2015-03-06
    • 2016-06-15
    • 2015-01-06
    相关资源
    最近更新 更多