我有一个Springboot应用程序,该应用程序具有产生和使用Kafka消息的KafkaConfig
组件。我还有一个数据库连接池管理器,用于初始化数据库池并创建数据库连接。这不是由Spring管理的,它是一个Java应用程序。我在jar中捆绑了这个connectionpool代码。这个连接池由CP类在Springboot应用程序中实现ApplicationListener<ApplicationReadyEvent>
来初始化。现在,我正在尝试使用由连接池初始化的代码从数据库中获取Kafka引导服务器信息。如何确定CP类之后初始化KafkaConfig
中的bean?
@Component
public class Startup implements ApplicationListener<ApplicationReadyEvent> {
@Override
public void onApplicationEvent(final ApplicationReadyEvent event) {
// connection pool getting initialized...
return;
}
}
这是一个存储库类,可从数据库中获取引导服务器信息
@Repository
public class Repo {
public string getKafkaServer(){
//Uses the ConnectionPool initialized by Startup class to get the
//bootstrap sever information.
}
}
这是Kafka Config类
@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.
}
}
关于启动代码加载后如何执行KafkaConfig
的任何想法?