Is it possible to get bean name during Condition evaluation?

Viewed 164

How would you retrieve the name of the bean annotated with @Conditional(MyCondition.class) from within the evaluation of the Condition itself?

static class MyCondition implements Condition {
  @Override
  public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
    if (shouldRegister) {
      return true;
    } else {
      System.out.println("Bean " + metadata.Can_I_Get_A_Reference_To_The_Bean_NameHere() + " will not be created.");
      return false;
    }
  }
}
0 Answers
Related