You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Claus Ibsen (Jira)" <ji...@apache.org> on 2023/04/03 13:59:00 UTC

[jira] [Commented] (CAMEL-19234) When looking up a mandatory bean, look it up through its type first

    [ https://issues.apache.org/jira/browse/CAMEL-19234?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17707981#comment-17707981 ] 

Claus Ibsen commented on CAMEL-19234:
-------------------------------------

In camel core project is only in use in EndpointHelper in resolveReferenceParameter method.
So I guess CEQ calls this code when you use endpoints.

So instead of changing this code, you should change resolveReferenceParameter in EndpointHelper to lookup by type, and fallback to convert if needed.


> When looking up a mandatory bean, look it up through its type first
> -------------------------------------------------------------------
>
>                 Key: CAMEL-19234
>                 URL: https://issues.apache.org/jira/browse/CAMEL-19234
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 3.0.0-M3
>            Reporter: Marco Bungart
>            Priority: Minor
>
> 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:
> {code:java|title=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);
> }
> ...
> {code}
> 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|https://camel.zulipchat.com/#narrow/stream/257302-camel-quarkus/topic/Resolution.20of.20.40Identifier.20dependency]



--
This message was sent by Atlassian Jira
(v8.20.10#820010)