How to debug Quarkus producer method - Stack Overflow

时间: 2025-01-06 admin 业界

I have a producer class which looks like this (SomeBean is here interface):

@ApplicationScoped
@JBossLog
public class DocumentCreatorFactory {
   @Produces
   @ApplicationScoped
   public List<SomeBean> getSomeBeans(@Any Instance<SomeBean> someBeans) {
      log.infof("######### Producer started: %d #########", documentCreators.stream().count());
      return someBeans.select(
          TagContext.Literal.of(Tag.CORE, Tag.CH)
      ).stream().toList();
   }

}

TagContext annotation looks as follows:

@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
public @interface TagContext {

   Tag[] value() default {Tag.CORE};

   final class Literal extends AnnotationLiteral<TagContext> implements TagContext {

      private final Tag[] value;

      public static Literal of(Tag... value) {
         return new Literal(value);
      }

      private Literal(Tag... value) {
         this.value = value;
      }

      @Override
      public Tag[] value() {
         return value;
      }
   }

}

Beans look like following:

@TagContext({Tag.CORE, Tag.CH})
@ApplicationScoped
@JBossLog
public class TagCoreAndChService implements SomeBean {
   @Override
   public void create() {
      log.infof("Core And Ch Some Bean Create");
   }
}

@TagContext
@ApplicationScoped
@JBossLog
public class TagCoreService implements SomeBean {
   @Override
   public void create() {
      log.infof("Core And Ch Some Bean Create");
   }
}

Why don't I get nothing written out on the console (logging) and I also can not debug this code inside Intellij?

SomeBean classes are being used in the following way:

@ApplicationScoped
@JBossLog
public class SomeBeanService {
   @Inject Instance<SomeBean> someBeans;
   @Inject @Any Instance<SomeBean> allSomeBeans;

   public void someProcessing(String inParam) {
// When we inspect count there is no bean found
      log.infof("Num of beans: %d", someBeans.stream().count());
      Instance<DocumentCreator> core = allSomeBeans.select(
          Literal.of(Tag.CORE, Tag.CH)
      );
// When we do this inside of the method we find some beans
      log.infof("Num of beans AFTER: %d", core.stream().count());
   }
}