gpt4 book ai didi

java - 如何创建 spring bean( "Kafka SINK"bean)以从配置服务器刷新上下文

转载 作者:行者123 更新时间:2023-12-02 02:10:09 25 4
gpt4 key购买 nike

我希望添加一个监听器,允许我从 Kafka 主题中提取消息。收到消息并根据应用程序名称进行过滤后,上下文刷新请求将发送到 Spring Config Server,Spring Config Server 会刷新 Spring Config Server 的属性。

但是,我的应用程序不是 Spring Boot 应用程序,而且我发现几乎我阅读的每个文档都需要 Spring Boot 应用程序来实现该目标。我是否有可能在没有 Spring boot 应用程序的情况下在 Spring Bean 中添加这样的流监听器?

我创建了一个 KafkaListener Bean。并且还添加了诸如 @EnableBinding(Sink.class) 之类的注释。但是我添加的注解会抛出java.lang.NoSuchMethodError,然后阻塞正在运行的进程,无法到达构造函数部分。

这是我的代码

@EnableBinding(Sink.class)
public class ApiApplication {
......


@StreamListener(Sink.INPUT)
public void configRefreshSink(RefreshRemoteApplicationEvent event) {
log.info("ApiApplication.configRefreshSink() called");
String applicationToRefreshContext = event.getDestinationService();
if (applicationToRefreshContext.startsWith(this.applicationName)) {
Set<String> keys = contextRefresher.refresh();
log.info("Received remote refresh request. Keys refreshed: " + keys);
}
log.info("Received remote refresh request. Destination: " + event.getDestinationService());
}
}

这些是我遇到的错误

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.context.support.ClassPathXmlApplicationContext]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org/springframework/util/Assert.notNull(Ljava/lang/Object;Ljava/util/function/Supplier;)V (loaded from file:xxxxx/repository/org/springframework/spring-core/4.3.22.RELEASE/spring-core-4.3.22.RELEASE.jar by

最佳答案

  1. 错误

NoSuchMethodError: org/springframework/util/Assert.notNull(Ljava/lang/Object;Ljava/util/function/Supplier;)V

表示Spring Framework的版本太旧-该方法是在Spring Framework 5.0中添加的

  • Spring Cloud Stream (@StreamListener) 需要 Spring Boot;没有启动就无法工作。
  • 关于java - 如何创建 spring bean( "Kafka SINK"bean)以从配置服务器刷新上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57332896/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com