Skip to content

Commit 084f96d

Browse files
committed
Sync documentation of main branch
1 parent 9558ff9 commit 084f96d

File tree

4 files changed

+115
-1
lines changed

4 files changed

+115
-1
lines changed

_generated-doc/main/infra/quarkus-maven-plugin-goals.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3856,7 +3856,7 @@ a| [[quarkus-maven-plugin-goal-track-config-changes-quarkus.recorded-build-confi
38563856
|`${basedir}/.quarkus`
38573857

38583858
a| [[quarkus-maven-plugin-goal-track-config-changes-quarkus.recorded-build-config.file]] quarkus.recorded-build-config.file
3859-
|`File`
3859+
|`String`
38603860
|
38613861

38623862
a| [[quarkus-maven-plugin-goal-track-config-changes-repoSession]] repoSession

_versions/main/guides/cdi-reference.adoc

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,113 @@ quarkus.arc.exclude-dependency.acme.artifact-id=acme-services <2>
163163
<1> Value is a group id for a dependency identified by name `acme`.
164164
<2> Value is an artifact id for a dependency identified by name `acme`.
165165
166+
[[string-based-qualifiers]]
167+
== String-Based Qualifiers
168+
169+
The `@Named` qualifier, which you might be familiar with, is a _string-based qualifier_.
170+
That is, it's the string value of the qualifier annotation who determines whether the qualifier matches or not.
171+
This is not type-safe and should not be the norm in CDI applications.
172+
Specific qualifier types should be preferred.
173+
174+
However, sometimes string-based qualifiers are necessary.
175+
In that case, avoid the `@Named` qualifier, because in CDI, it works differently to all other qualifiers.
176+
177+
Specifically: if the only qualifier a bean has is `@Named`, it also automatically gets `@Default`.
178+
This means that if multiple beans of the same type exist, one of them without qualifiers and the others with `@Named`, they _all_ get the `@Default` qualifier and bean resolution will error with ambiguity.
179+
For example:
180+
181+
[source,java]
182+
----
183+
@ApplicationScoped
184+
public class Producers {
185+
@Produces
186+
MyBean produce() {
187+
...
188+
}
189+
190+
@Produces
191+
@Named("foo")
192+
MyBean produceFoo() {
193+
...
194+
}
195+
}
196+
197+
@ApplicationScoped
198+
public class Consumer {
199+
@Inject
200+
MyBean bean;
201+
}
202+
----
203+
204+
In this case, the `Consumer#bean` injection point will cause ambiguity error, because both `MyBean` producers will have the `@Default` qualifier.
205+
206+
Instead of `@Named`, use `@io.smallrye.common.annotation.Identifier`.
207+
This is a regular qualifier that works like all others.
208+
So if we rewrite the example to use `@Identifier`:
209+
210+
[source,java]
211+
----
212+
@ApplicationScoped
213+
public class Producers {
214+
@Produces
215+
MyBean produce() {
216+
...
217+
}
218+
219+
@Produces
220+
@Identifier("foo")
221+
MyBean produceFoo() {
222+
...
223+
}
224+
}
225+
226+
@ApplicationScoped
227+
public class Consumer {
228+
@Inject
229+
MyBean bean;
230+
}
231+
----
232+
233+
Only the first producer will get the `@Default` qualifier, the second will not.
234+
Hence, there will be no error and everything will work as expected.
235+
236+
=== When To Use `@Named`?
237+
238+
There is one case where `@Named` is the right thing to use: specifying an external identifier for a different language that doesn't support dependency injection directly.
239+
240+
For example:
241+
242+
[source,java]
243+
----
244+
@ApplicationScoped
245+
@Named("myBean")
246+
public class MyBean {
247+
public String getValue() {
248+
...
249+
}
250+
}
251+
252+
@ApplicationScoped
253+
public class Consumer {
254+
@Inject
255+
MyBean bean;
256+
}
257+
----
258+
259+
As you can see, in the application code, the bean is injected without a qualifier.
260+
The bean name is only used to refer to the bean in the other language.
261+
262+
Historically, the most common external language that used bean names was JSF.
263+
In Quarkus, we have xref:qute-reference.adoc#injecting-beans-directly-in-templates[Qute].
264+
In a Qute template, one would refer to the bean using its name:
265+
266+
[source]
267+
----
268+
The current value is {inject:myBean.value}.
269+
----
270+
271+
Outside of this use-case, just use `@Identifier`.
272+
166273
== Native Executables and Private Members
167274

168275
Quarkus is using GraalVM to build a native executable.

_versions/main/guides/cdi.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ This bean would be assignable to `@Inject @Superior Translator` and `@Inject @Su
171171
The reason is that `@Inject Translator` is automatically transformed to `@Inject @Default Translator` during typesafe resolution.
172172
And since our `SuperiorTranslator` does not declare `@Default` only the original `Translator` bean is assignable.
173173

174+
NOTE: The `@Named` qualifier, which you might be familiar with, is somewhat different in CDI to all other qualifiers.
175+
See the xref:cdi-reference.adoc#string-based-qualifiers[corresponding section] in CDI Reference Guide for why you typically shouldn't use it.
176+
174177
[[bean-scope]]
175178
== Looks good. What is the bean scope?
176179

_versions/main/guides/hibernate-reactive.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ Here's a list of things to pay attention when using Hibernate Reactive in Quarku
317317
* This extension only considers the default persistence unit at the moment:
318318
it's not possible to configure multiple persistence units,
319319
or even a single named persistence unit.
320+
* This extension does not support xref:hibernate-orm.adoc#database-approach[database-based multitenancy]
321+
or xref:hibernate-orm.adoc#schema-approach[schema-based multitenancy] at the moment.
322+
xref:hibernate-orm.adoc#discriminator-approach[Discriminator-based multitenancy], on the other hand, is expected to work correctly.
323+
See https://github.com/quarkusio/quarkus/issues/15959.
320324
* This extension cannot be used at the same time as Hibernate ORM.
321325
See https://github.com/quarkusio/quarkus/issues/13425.
322326
* Integration with the Envers extension is not supported.

0 commit comments

Comments
 (0)