This can be a possible solution: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/beans/factory/config/ObjectFactoryCreatingFactoryBean.html
Or maybe this way with @Async
https://www.baeldung.com/spring-async#:~:text=Simply%20put%2C%20annotating%20a%20method,for%20async%20processing%20if%20necessary.