spring-kafka - KafkaListener 没有使用“#{__listener.getContainerFactory()}”解析 containerFactory
问题描述
我正在使用以下方法来获取 KafkaListener 属性。但它不解析 containerFactory 值。但它适用于主题和 groupId。
@KafkaListener(topics = "#{__listener.getTopics()}",
groupId = "#{__listener.getGroupId()}",
containerFactory = "#{__listener.getContainerFactory()}")
public void sampleTestTopicListener(@Payload byte[] data,
.....
@Value("sampleTestListenerContainerFactory")
private String containerFactory ;
public String getContainerFactory(){
return containerFactory;
}
....
Spring-kafka-2.2.5.RELEASE
I get the following error :
A component required a bean named '#{__listener.getContainerFactory()}' that could not be found.
Changing the containerFactory value to "sampleTestListenerContainerFactory" instead of spEL, it works fine.
如何使用当前的 beans 属性设置它?
解决方案
该注释containerFactory
上的选项@KafkaListener
不能作为 SpEL 表达式。不过,您可以使用属性占位符解析。像这样:
containerFactory = "${sampleTestListenerContainerFactory}"
但无论如何最好使用一个真实的bean名称:KafkaListenerContainerFactory
真的必须是一个bean......
另一个注意事项:Apache Kafka 2.2.5 的 Spring 版本不支持。它在很久以前就达到了生命的尽头。保持最新版本更实用:https ://spring.io/projects/spring-kafka#learn
推荐阅读
- php - 如果修改了 api 结果,如何更新表中的列
- javascript - 如何在 PWA 中以编程方式将显示从独立切换到全屏
- docker - Jenkinsfile Pipeline:到达主机边车的IP
- java - 使用 xml 文件连接到数据库 - java
- postgresql - WSO2 企业集成商 DSS
- r - 为什么如果块输出因停止/警告而异?
- javascript - 如何在 vis.js 时间轴中对嵌套组进行排序?
- mysql - SQL在字符串中查找单词,按找到的单词数对结果进行排序
- c# - 将事件处理程序添加到 ResourceDictionary 内的 ContextMenu 内的 MenuItem
- c# - 使用 roslyn 检查 .csproj 文件中的 ProjectReferences