【问题标题】:Spring Integration Kafka Configuration - Errors in EclipseSpring Integration Kafka 配置 - Eclipse 中的错误
【发布时间】:2016-10-24 04:55:00
【问题描述】:

我使用 Eclipse 作为 IDE。我有一个非常基本的配置 XML 文件,它不会验证,因此会阻止 Eclipse 运行任何东西。我错过了什么?

这是验证错误(我看到问题视图):

这是我的配置 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:int="http://www.springframework.org/schema/integration"
    xmlns:int-kafka="http://www.springframework.org/schema/integration/kafka"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/integration/kafka http://www.springframework.org/schema/integration/kafka/spring-integration-kafka.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/task http://www.springframework.org/schema/task/spring-task.xsd">

    <int:channel id="inputToKafka" />
    <int-kafka:outbound-channel-adapter
        id="kafkaOutboundChannelAdapter" kafka-template="template"
        auto-startup="false" channel="inputToKafka" topic="replicated-topic-1"
        message-key-expression="'bar'" partition-id-expression="2">
    </int-kafka:outbound-channel-adapter>

    <bean id="template" class="org.springframework.kafka.core.KafkaTemplate">
        <constructor-arg>
            <bean class="org.springframework.kafka.core.DefaultKafkaProducerFactory">
                <constructor-arg>
                    <map>
                        <entry key="bootstrap.servers" value="192.168.33.21:9092,192.168.33.22:9092,192.168.33.23:9092" />
                    </map>
                </constructor-arg>
            </bean>
        </constructor-arg>
    </bean>

    <int-kafka:message-driven-channel-adapter
        id="kafkaListener"
        listener-container="listenerContainer"
        auto-startup="false"
        phase="100"
        send-timeout="5000"
        channel="nullChannel"
        error-channel="errorChannel" />

    <bean id="listenerContainer" class="org.springframework.kafka.listener.KafkaMessageListenerContainer">
        <constructor-arg>
            <bean class="org.springframework.kafka.core.DefaultKafkaConsumerFactory">
                <constructor-arg>
                    <map>
                        <entry key="bootstrap.servers" value="192.168.33.21:9092,192.168.33.22:9092,192.168.33.23:9092" />
                    </map>
                </constructor-arg>
            </bean>
        </constructor-arg>
        <constructor-arg name="topics" value="replicated-topic-1" />
    </bean>

</beans>

【问题讨论】:

    标签: spring-integration apache-kafka


    【解决方案1】:

    如果这些只是虚假错误并且应用程序运行正常,则仅表示您正在解析 spring-integration-core 架构 here 的在线版本。请参阅该架构顶部的重要说明,了解为什么它不是当前版本。

    您可以通过使用 spring-aware eclipse(例如 STS 或 Spring IDE 插件)来解决这个问题,并在项目上设置 spring 性质,以便从类路径而不是 Internet 正确解析架构。

    或者您可以转到 eclipse 首选项中的 XML 目录并配置架构映射以正确指向 4.3 版本的架构。

    如果它确实是运行时问题(应用程序无法运行),那么这意味着您的类路径中的 spring-integration-core 版本不正确 - 您应该使用 maven 或 gradle 来传递正确的版本。如果是手动构建项目类路径,则需要spring-integration-core 4.3.2或更高版本(当前版本为4.3.4)。

    【讨论】:

    • 感谢您的回复加里。它似乎不是运行时问题。我将测试它是否可以使用正确的版本解决并更新我发现的内容。
    • 好的,所以我尝试了 STS,所有错误都消失了。也没有运行时错误。但是,无论我在计划 Eclipse 中尝试什么,我都无法摆脱错误。一件事导致另一件事,冲突太多了。我应该考虑将 Java DSL 用于 Spring 集成的另一个原因
    • 您应该能够通过首选项中的 XML 目录重温它。但是,当有 Spring 插件可以帮助您时,为什么还要挣扎呢?显然,DSL 是一种更现代的方式来配置流,但有些人喜欢 XML,一旦你把所有东西都对齐了,这种模式的东西就不是那么难了。
    猜你喜欢
    • 1970-01-01
    • 2015-12-12
    • 1970-01-01
    • 2017-07-30
    • 1970-01-01
    • 2016-01-28
    • 1970-01-01
    • 2020-07-25
    • 2020-09-09
    相关资源
    最近更新 更多