From 28b8c091d7632da4f263fe67bf44be817a3d50d6 Mon Sep 17 00:00:00 2001 From: Matej Novotny Date: Mon, 13 Sep 2021 23:52:49 +0200 Subject: [PATCH] Allow using @Priority within stereotypes. --- .../main/asciidoc/core/definition.asciidoc | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/spec/src/main/asciidoc/core/definition.asciidoc b/spec/src/main/asciidoc/core/definition.asciidoc index 39e29bb2..9f453e9b 100644 --- a/spec/src/main/asciidoc/core/definition.asciidoc +++ b/spec/src/main/asciidoc/core/definition.asciidoc @@ -729,13 +729,12 @@ A stereotype encapsulates any combination of: A stereotype may also specify that: * all beans with the stereotype have defaulted bean names, or that -* all beans with the stereotype are alternatives. +* all beans with the stereotype are alternatives, or that +* all beans with the stereotype have predefined `@Priority`. A bean may declare zero, one or multiple stereotypes. -// TODO how about we finally allowed declaring `@Priority` on stereotypes? - [[defining_new_stereotype]] ==== Defining new stereotypes @@ -837,6 +836,28 @@ We may specify that all mock objects are alternatives: public @interface Mock {} ---- +[[priority_stereotype]] + +===== Declaring stereotype with `@Priority` + +A stereotype may declare a `@Priority` annotation which functions as a means of enabling and ordering affected alternatives, interceptors, and decorators (in {cdi_full}). + +If a bean declares two different stereotypes that declare different priority values, the bean must explicitly declare a `@Priority` annotation. If the bean does not explicitly declare priority, the container automatically detects the problem and treats it as a definition error. + +If a bean explicitly declares priority, any priority values declared by stereotypes are ignored. + +Following sample shows a stereotype that can be used to mark bean as globally enabled alternative: + +[source, java] +---- +@Alternative +@Priority(Interceptor.Priority.APPLICATION + 5) +@Stereotype +@Target(TYPE) +@Retention(RUNTIME) +public @interface Mock {} +---- + [[stereotypes_with_additional_stereotypes]] ===== Stereotypes with additional stereotypes