Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [config-dev] What priority means in Jakarta


Yes, it mentions highest priority, but it doesn’t say how the highest priority is calculated. 

If we check the javadoc for javax.enterprise.inject.spi.AfterTypeDiscovery#getAlternatives:

  the list of enabled alternatives for the application, sorted by priority in ascending order

The spec doesn’t seem to be clear to how Alternatives execute, so lets look into Decorators:

  Decorators with the smaller priority values are called first.

And the javadoc for javax.enterprise.inject.spi.AfterTypeDiscovery#getDecorators:

  the list of enabled decorators for the application, sorted by priority in ascending order.

So I assume that there is some consistency here and the order returned in this method calls is also the executing order (at least for Decorators, I’ll have to confirm for Alternatives).

And Observers:

  Observers with smaller priority values are called first.

Maybe there are cases where CDI is doing the opposite (biggest priority number), but it seems that the majority of cases is lowest priority number = first execution.

The interesting thing is that the annotation spec leaves this open to the consumer:

  The effect of using the Priority annotation in any particular instance is defined by other specifications that define the use of a specific class.

But this is not really a good thing in my opinion. As we were discussing the way that priority order should be consistent across all Jakarta platform and not defined at each specification, or we end up with this mess where we never know how it works for each case.


On 14 Oct 2021, at 16:21, Emily Jiang <emijiang6@xxxxxxxxxxxxxx> wrote:

Further to today's discussion, I spent a bit more time looking at the usage in CDI and try to recall what we discussed in the past regarding priority understanding. For priority used for overwrite reasons, such as converter and configsources.

We mainly discussed the invocation order for interceptors etc. No example was found on overwrite purpose as we used in Config.

I did further digging and found in CDI spec, the following explains clearly that highest priority wins.

All the beans left are alternatives with a priority, or producer methods or fields of beans that are alternatives with a priority, then the container will determine the highest priority value, and eliminate all beans, except for alternatives with the highest priority and producer methods and fields of alternatives with the highest priority value. If there is exactly one bean remaining, the container will select this bean, and the ambiguous dependency is called resolvable.

The above sentence clearly says the highest priority wins. MP Config priority is consistent with this behaviour.


config-dev mailing list
To unsubscribe from this list, visit

Back to the top