quarkus 中的程序化 运行-time injection/auto-wiring

Programmatic run-time injection/auto-wiring in quarkus

我正在寻找一种在 Quarkus 中执行 bean 运行时注入的方法。我意识到这可能是 quarkus 的非正统方法,以及反模式的东西,所以不需要指出这一点,我完全知道 :)

我正在寻找的是一种在运行时构建 bean 的方法,并具有从 Quarkus 上下文注入的任何带注释的属性。

在 Spring 引导中,我将通过 spring 引导正常初始化的 bean 获取应用程序上下文,使用工厂上的 ApplicationContextAware interface to inject the application context. I would then use that as a factory by calling ApplicationContext.getAutowireCapableBeanFactory() to get the auto-wire factory and using the autowireBean 方法在运行时自动装配我的 bean。我想知道在 Quarkus 中是否可以做类似的事情?

这与这个问题类似。 How to programmatically inject a Java CDI managed bean into a local variable in a (static) method

javax.enterprise.inject.spi.CDI.current().getBeanManager().select(C.class).get()

要确保 bean class 被管理,请使用 io.quarkus.arc.Unremovable 注释。