Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-19234

camel-core - When looking up a mandatory bean, look it up through its type first

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 4.0-M3, 4.0.0
    • camel-core
    • None
    • Unknown

    Description

      Currently, when we look up a mandatory bean which type we know, we perform the lookup with the bean's name and convert it to the requested type:

      CamelContextHelper.java
      ...
      public static <T> T mandatoryLookupAndConvert(CamelContext context, String name, Class<T> beanType) {
          Object value = lookup(context, name);
          if (value == null){
              throw new NoSuchBeanException(name, beanType.getName());
          }
          return convertTo(context, beanType, value);
      }
      ...
      

      Source: https://github.com/apache/camel/blob/main/core/camel-support/src/main/java/org/apache/camel/support/CamelContextHelper.java#L245

      This leads to problem with the current implementation of https://github.com/apache/camel-quarkus/issues/4725, where we introduced automatic registration of beans annotated with @Identifier . When several beans with the same @Identifier("<name>") but different types are present. We think we can prevent this problem when we modify above method to do a lookup(...) with the type information, and only do the lookup(...) without type information if the lookup(...)with type information yielded no result.

      FTR: relevant zulip chat

      Attachments

        Issue Links

          Activity

            People

              davsclaus Claus Ibsen
              turing85 Marco Bungart
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: