Does Quarkus have an annotation or method similar to @ConditionalOnBean?

104 Views Asked by At

I am developing an extension for Quarkus, and I'm facing certain problems. Within the deployment module, I need to decide whether or not to instantiate beanB depending on the existence of a user-defined beanA.


    @BuildStep
    void registerBeanProducers(BuildProducer<AdditionalBeanBuildItem> additionalBeans,
                               BuildProducer<ReflectiveClassBuildItem> reflectiveClasses,
                               CombinedIndexBuildItem combinedIndexBuildItem) {
        AdditionalBeanBuildItem.Builder builder = AdditionalBeanBuildItem.builder().setUnremovable();

        if (container has user-defined beanA) {
            builder.addBeanClass(beanB.class);
        }
        additionalBeans.produce(builder.build());
    }

Are there any relevant materials that I can refer to for this aspect, or could you provide a general direction of thought?

@BuildStep
    void registerBeanProducers(BeanArchiveIndexBuildItem beanArchiveIndexBuildItem,
                               BuildProducer<AdditionalBeanBuildItem> additionalBeans,
                               BuildProducer<ReflectiveClassBuildItem> reflectiveClasses) {
        Collection<ClassInfo> classInfos = beanArchiveIndexBuildItem.getIndex().getKnownUsers(beanA.class);
        if (!classInfos.isEmpty()) {
            AdditionalBeanBuildItem.Builder builder = AdditionalBeanBuildItem.builder().setUnremovable();
            builder.addBeanClass(beanB.class);
            additionalBeans.produce(builder.build());
        }
    }


0

There are 0 best solutions below