Java ApplicationEvent上的springboot kafka
我有一个Springboot应用程序,它有一个生成和使用Kafka消息的组件。我还有一个DB connectionpool管理器,它初始化DB池并创建DB连接。这不是由Spring管理的,它是一个Java应用程序。我在jar中捆绑了这个connectionpool代码。此连接池由在Springboot应用程序中实现Java ApplicationEvent上的springboot kafka,java,spring-boot,apache-kafka,Java,Spring Boot,Apache Kafka,我有一个Springboot应用程序,它有一个生成和使用Kafka消息的组件。我还有一个DB connectionpool管理器,它初始化DB池并创建DB连接。这不是由Spring管理的,它是一个Java应用程序。我在jar中捆绑了这个connectionpool代码。此连接池由在Springboot应用程序中实现ApplicationListener的CP类初始化。现在,我尝试使用connectionpool初始化的代码从数据库中获取Kafka引导服务器信息。如何确保我的kafkanconfi
ApplicationListener
的CP类初始化。现在,我尝试使用connectionpool初始化的代码从数据库中获取Kafka引导服务器信息。如何确保我的kafkanconfig
中的bean在CP类之后初始化
@Component
public class Startup implements ApplicationListener<ApplicationReadyEvent> {
@Override
public void onApplicationEvent(final ApplicationReadyEvent event) {
// connection pool getting initialized...
return;
}
}
这是Kafka配置类
@Component
@EnableKafka
public class KafkaConfig {
@Autowired
Repo repo;
@Bean
public consumerFactory<String, String> consumerFactory(){
String bootstrapServer = repo.getKafkaServer();
//The bootstrapServer is coming as null and this code executes before the
//Startup class gets initialized.
}
}
@组件
@使能卡夫卡
公共级卡夫卡康菲{
@自动连线
回购;
@豆子
公共消费者工厂消费者工厂(){
字符串bootstrapServer=repo.getKafkaServer();
//bootstrapServer为null,此代码在
//初始化启动类。
}
}
你知道如何在启动代码加载后执行kafkanconfig
吗
@Component
@EnableKafka
public class KafkaConfig {
@Autowired
Repo repo;
@Bean
public consumerFactory<String, String> consumerFactory(){
String bootstrapServer = repo.getKafkaServer();
//The bootstrapServer is coming as null and this code executes before the
//Startup class gets initialized.
}
}