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?
  • From: Ladislav Thon <lthon@xxxxxxx>
  • Date: Mon, 14 Jul 2025 07:30:37 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=ibm.com; dmarc=pass action=none header.from=ibm.com; dkim=pass header.d=ibm.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mxaMygEY1qDKVJqgZNxPw9pIvvkYT2BGRMWfTmsqM6M=; b=Zc8ibMXmRR3uHX5IWoqDqQIA6FnoxgPbnNToVV2367udJiy2BupPmr2aPA06UgSdnLj1/tM/o2BASCC2IcZ2T8+pc598ROUuFkU64O8xp+UufIByEkLIQERVl11gMfhzs0rpyizV3rNYTg8AxGEMzeEwwgmGZPMtgODmTgkpu0R5Du0W+4n6nnBj8civVejKdxO4bsrpM6RKqBBbE9xOLJoTCcOLoLA0FY2b2mCm45VAWE2pkT0yl3dW0BR/ZTDyvaohYYzAgsCL/E0Yjr3ngLQw0yMdBeDuIp39X7L86BZAoS42s97zqYsq8RbAmU6DAD/kxZqYmpPdI3zDFzuI0w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=n4aKcsfLm5feMikrxtk50QcyU/MgrBJkTP4saHDCbGs9tu70aCdPPleroXXrO5i7Rw/o5VrFjEakUYd3L05TZoVjy8jfbpAtP1X3j2KFn2JKynZW4QD+Md4gLpWal6aD0v+rDOixfJSaosSW8SX+l9xJ2PlouwMKMNrgAinQ8lwIrdssAWKMZmGMiuRbsnRYzPhkAh7WoTn6AakbS3we6h5BkUp4zXiaFcQXePcglGZ3GS4VaSdhRqkhYLLOEBxL8SX1H4H3nGxw4rZ52SHm5FFUO0xzXM6xjodDFdFVWqRyIBJsR2OGEzR8P6R/7UjP+C0WcRS3q3Tfy2rKA6vo3Q==
  • Delivered-to: cdi-dev@xxxxxxxxxxx
  • List-archive: <https://www.eclipse.org/mailman/private/cdi-dev/>
  • List-help: <mailto:cdi-dev-request@eclipse.org?subject=help>
  • List-subscribe: <https://www.eclipse.org/mailman/listinfo/cdi-dev>, <mailto:cdi-dev-request@eclipse.org?subject=subscribe>
  • List-unsubscribe: <https://www.eclipse.org/mailman/options/cdi-dev>, <mailto:cdi-dev-request@eclipse.org?subject=unsubscribe>
  • Msip_labels:
  • Thread-index: AQHb9IWJj4xryFUYyUmjHElVc2SYgbQxOEVc
  • Thread-topic: [EXTERNAL] Re: [cdi-dev] What is the purpose of @Priority on Producers?

Hi,

I don't think you can produce interceptors, but Ondro is exactly right about alternatives. Since it wasn't possible to put @Priority on methods for a long time, the typesafe resolution algorithm contains a "hack" where producers inherit priority from their declaring beans. That is no longer necessary — producers can declare priority on their own.

Priority may affect order of beans that you may iterate on an Instance, but that has never been specified and so is implementation-specific.

LT


From: cdi-dev <cdi-dev-bounces@xxxxxxxxxxx> on behalf of Ondro Mihályi via cdi-dev <cdi-dev@xxxxxxxxxxx>
Sent: Monday, July 14, 2025 08:06
To: cdi developer discussions <cdi-dev@xxxxxxxxxxx>
Cc: Ondro Mihályi <mihalyi@xxxxxxxxxxx>
Subject: [EXTERNAL] Re: [cdi-dev] What is the purpose of @Priority on Producers?
 
This Message Is From an External Sender
This message came from outside your organization.
 
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

_______________________________________________
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