【发布时间】:2019-03-22 13:43:38
【问题描述】:
我在我的 yaml 文件中配置了 10 个 kafka 主题,我需要在应用程序启动时创建所有主题。但我不明白如何使用 List 来做到这一点。我可以创建一个 bean:
@Bean
public NewTopic newTopic() {
return new NewTopic("topic-name", 5, (short) 1);
}
但现在我有列表配置:
@PostConstruct
public void init(){
Map<String, TopicProperties.Topic> topics = this.topics.getTopics();
for (Map.Entry<String, TopicProperties.Topic> topicEntry : topics.entrySet()) {
TopicProperties.Topic topic = topicEntry.getValue();
String topicName = topic.getTopicName();
int partitions = topic.getNumPartitions();
short replicationFactor = topic.getReplicationFactor();
//how can I create new bean of NewTopic?
}
}
【问题讨论】:
标签: spring spring-boot dependency-injection spring-kafka