You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/main/asciidoc/config-reference.adoc
+62Lines changed: 62 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -706,6 +706,68 @@ options exposed by a `org.eclipse.microprofile.config.Config` instance. Which me
706
706
build configuration options since MicroProfile Config specification allows configuration sources not to expose all the property names they provide to users.
707
707
====
708
708
709
+
== Config property values injected during static intialization phase
710
+
711
+
Quarkus collects the config property values injected in CDI beans during xref:writing-extensions.adoc#bootstrap-three-phases[static intialization phase].
712
+
The collected values are then compared with their runtime initialization counterparts and if a mismatch is detected the application startup fails.
713
+
How can it happen?
714
+
For example, let's have a CDI bean `org.acme.MyBean`.
715
+
`MyBean` injects a `@ConfigProperty` of name `foo` and is initialized during the native build.
716
+
The config property does not exist during the native build and so the default value `bar` is used.
717
+
But later, when the application is started the property is defined with a system property: `-Dfoo=baz`.
718
+
This would lead to inconsistent state and unexpected behavior.
719
+
Therefore, Quarkus would fail in this situation by default.
// this observer method is notified during STATIC_INIT...
738
+
}
739
+
}
740
+
----
741
+
<1> The config property is injected when the bean is created and the value is fixed.
742
+
<2> In this particular case, the observer `@Initialized(ApplicationScoped.class)` caused the initialization of the bean. However, there are other possibilities. For example, some extensions initialize components during static intialization phase.
743
+
744
+
You can annotate an injected field/parameter with `@io.quarkus.runtime.annotations.StaticInitSafe` to mark the injected configuration object as safe to be initialized during the static intialization phase.
0 commit comments