Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdi-dev] What is the purpose of @Priority on Producers?

In short, allowing @Priority on producer methods makes producer methods equally powerful than defining beans by classes.

I’m not sure if Priority plays role in the order of beans, maybe it impacts the order of beans returned from the iterator if an injected Instance.

But Priority has a very important side-effect on beans marked as @Alternative - it enables them automatically, without adding them to beans.xml. And it also automatically enables interceptors without adding them to beans.xml, besides ordering them.

Both alternative beans and interceptors can be produced by a producer. Then you are able to enable them (and order them in case of multiple interceptors) in the same way as if they are defined by a class.

Ondro



On Sat, 12 Jul 2025 at 18:31, hantsy bai via cdi-dev <cdi-dev@xxxxxxxxxxx> wrote:
In this https://jakartaee.github.io/cdi/2024/02/27/whats-new-in-cdi41.html, there is a new feature in CDI 4.1 that adds @ Priority to producers. 

For example, if the same interface with different implement, we can identify them with qualifiers. Two producers for this case with @ Priority is meaningless.

And the beans instantation ordering can be detected by the dependencies. 

Is there a simple example to demonstrate it resolves the current issue?


---

Regards,

Hantsy Bai

Self-employed consultant, fullstack developer, agile coach, freelancer/remote worker

GitHub: https://github.com/hantsy

Twitter: https://twitter.com/@hantsy

Medium: https://medium.com/@hantsy
_______________________________________________
cdi-dev mailing list
cdi-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/cdi-dev

Back to the top