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: quarkus-workshop-super-heroes/docs/src/docs/asciidoc/optional-quarkus-extension/quarkus-extension.adoc
+21-15
Original file line number
Diff line number
Diff line change
@@ -135,10 +135,29 @@ For this, what do we need:
135
135
The _runtime_ part of an extension contains only the classes and resources required at runtime.
136
136
For the version extension, it would be a single class that prints the version.
137
137
138
+
First, let's create the configuration class that will allow users to dynamically configure whether the version should be printed:
139
+
[example, role="cta"]
140
+
--
141
+
142
+
Under the `runtime` module, create the `src/main/java` directory, and, in this directory, create a new interface named `io.quarkus.workshop.superheroes.version.runtime.VersionConfig` with the following content:
The `@ConfigMapping` annotation declares `VersionConfig` as a configuration interface which configuration properties are prefixed with `quarkus.version` prefix. It is also used in CDI aware environments to scan and register Config Mappings.
150
+
151
+
The `@ConfigRoot` annotation declares that the configuration is available during runtime.
152
+
153
+
The `@WithDefault("true")` is used to declare the default value returned when `enabled()` is called.
154
+
155
+
By default, the name of the property is derived from what's declared in the `prefix` attribute inside `@ConfigMapping` plus the name of the method. In our case, the user-configured property will be `quarkus.version.enabled`.
156
+
138
157
[example, role="cta"]
139
158
--
140
159
141
-
In the runtime module, create the `src/main/java` directory, and, in this directory, the `io.quarkus.workshop.superheroes.version.runtime.VersionRecorder` class with the following content:
160
+
Still in the `runtime` module, create the `io.quarkus.workshop.superheroes.version.runtime.VersionRecorder` class with the following content:
142
161
143
162
[source,java]
144
163
----
@@ -160,27 +179,14 @@ The version extension consists of a single build step that extracts the version
160
179
161
180
[example, role="cta"]
162
181
--
163
-
First, let's create the configuration class that will allow users to dynamically configure whether the version should be printed:
164
-
165
-
Under the `deployment` module, create new class `io.quarkus.workshop.superheroes.version.deployment.VersionConfig` with the following content:
The `@ConfigRoot` annotation declares `VersionConfig` as a configuration class which configuration properties are prefixed with `quarkus.` prefix.
174
-
175
-
The `@ConfigItem` is used to declare individual configuration properties. By default, the name of the property is derived from the name of the field. In our case, the user-configured property will be `quarkus.version.enabled`.
176
182
177
183
Next, open the `ExtensionVersionProcessor` class, and update the content to be:
Copy file name to clipboardexpand all lines: quarkus-workshop-super-heroes/super-heroes/extension-version/deployment/src/main/java/io/quarkus/workshop/superheroes/version/deployment/ExtensionVersionProcessor.java
Copy file name to clipboardexpand all lines: quarkus-workshop-super-heroes/super-heroes/extension-version/deployment/src/main/java/io/quarkus/workshop/superheroes/version/deployment/VersionConfig.java
Copy file name to clipboardexpand all lines: quarkus-workshop-super-heroes/super-heroes/extension-version/runtime/src/main/java/io/quarkus/workshop/superheroes/version/runtime/VersionRecorder.java
0 commit comments