【发布时间】:2019-08-03 20:41:49
【问题描述】:
我希望添加一个监听器,允许我从 Kafka 主题中提取消息。在收到消息并根据应用程序名称进行过滤后,会将上下文刷新请求发送到 Spring Config Server,后者会刷新 Spring Config Server 中的属性。
但是,我的应用程序不是 Spring Boot 应用程序,我发现几乎我阅读的每个文档都需要 Spring Boot 应用程序来实现该目标。有没有可能我可以在没有 Spring 启动应用程序的情况下在 Spring Bean 中添加这样的流侦听器?
我创建了一个 bean KafkaListener。并且还添加了@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
【问题讨论】:
标签: java spring apache-kafka spring-cloud-stream spring-bean