Este conteúdo não está disponível no idioma selecionado.
Chapter 10. Using custom configuration converters as configuration values
You can store custom types as configuration values by implementing org.eclipse.microprofile.config.spi.Converter<T> and adding its fully qualified class name into the META-INF/services/org.eclipse.microprofile.config.spi.Converter file.
Prerequisites
-
You have created the Quarkus
config-quickstartproject.
Procedure
Include the fully qualified class name of the converter in your
META-INF/services/org.eclipse.microprofile.config.spi.Converterservice file as shown in the following example:org.acme.config.MicroProfileCustomValueConverter org.acme.config.SomeOtherConverter org.acme.config.YetAnotherConverter
org.acme.config.MicroProfileCustomValueConverter org.acme.config.SomeOtherConverter org.acme.config.YetAnotherConverterCopy to Clipboard Copied! Toggle word wrap Toggle overflow Implement the converter class to override the convert method:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteYour custom converter class must be
publicand must have apublicno-argument constructor. Your custom converter class cannot beabstract.Use your custom type as a configuration value:
@ConfigProperty(name = "configuration.value.name") MicroProfileCustomValue value;
@ConfigProperty(name = "configuration.value.name") MicroProfileCustomValue value;Copy to Clipboard Copied! Toggle word wrap Toggle overflow
10.1. Setting custom converters priority Copiar o linkLink copiado para a área de transferência!
The default priority for all Quarkus core converters is 200 and for all other converters it is 100. However, you can set a higher priority for your custom converters using the javax.annotation.Priority annotation.
The following procedure demonstrates an implementation of a custom converter MicroProfileCustomValue that is assigned a priority of 150 and will take precedence over MicroProfileCustomValueConverter which has a value of 100.
Prerequisites
-
You have created the Quarkus
config-quickstartproject.
Procedure
Add the following import statements to your service file:
package org.acme.config; import javax.annotation.Priority; import org.eclipse.microprofile.config.spi.Converter;
package org.acme.config; import javax.annotation.Priority; import org.eclipse.microprofile.config.spi.Converter;Copy to Clipboard Copied! Toggle word wrap Toggle overflow Set a priority for your custom converter by annotating the class with the
@Priorityannotation and passing it a priority value:Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIf you add a new converter, you must list it in the
META-INF/services/org.eclipse.microprofile.config.spi.Converterservice file.