0
votes

This question is about the proper way to read configuration in a REST service in a portable way, e.g. should run on Thorntail 2.4.0 and Wildfly 15.

This was the original implementation suggested by Thorntail

@Inject
    @org.wildfly.swarm.spi.runtime.annotations.ConfigurationValue("swarm.port.offset")
private Optional<String> portOffset;

This was not working in WildFly 15 so we changed this code in the following way:

@Inject
@ConfigProperty(name="swarm.port.offset")
private Optional<String> portOffset;

And provided the system property is set, it works nicely.

However, back in Thorntail, it generates the following exception:

org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type Optional with qualifiers @ConfigProperty
at injection point [BackedAnnotatedField] @Inject @ConfigProperty private com.my-company.core.internal.util.ZookeeperRegistry.portOffset
at com.my-company.core.internal.util.ZookeeperRegistry.portOffset(ZookeeperRegistry.java:0) WELD-001475: The following beans match by type, but none have matching qualifiers: - Producer Method [Optional] with qualifiers [@Any @ConfigurationValue] declared as [[UnbackedAnnotatedMethod] @ConfigurationValue @Dependent @Produces org.wildfly.swarm.container.runtime.cdi.ConfigurationValueProducer.produceOptionalConfigValue(InjectionPoint)]

Many thanks in advance.

1
This almost looks like you only have a dependency on the MicroProfile Config API (org.eclipse.microprofile.config:microprofile-config-api), but not on the Thorntail MP Config fraction (io.thorntail:microprofile-config). Isn't that the case?Ladicek

1 Answers

0
votes

The code runs finally on both environments, with a single pom file.

I detail below the solution adopted.

  1. Used @ConfigProperty, not @org.wildfly.swarm.spi.runtime.annotations.ConfigurationValue
  2. Use @Any @ConfigProperty, resolved WELD-001475
  3. In terms of maven dependencies, I included this dependency regardless of whether we are building for Thorntail or for WildFLy

    <dependency>
        <groupId>org.eclipse.microprofile.config</groupId>
        <artifactId>microprofile-config-api</artifactId>
    </dependency>
    

The actual version is resolved using dependencyManagement for the Eclipse microprofile:

<dependencyManagement>
    <dependencies>
        <dependency>
           <groupId>org.eclipse.microprofile</groupId>
           <artifactId>microprofile</artifactId>
           <version>2.2</version>
           <type>pom</type>
           <scope>import</scope>
       </dependency>   
...
</dependencyManagement>
  1. Maven profiles are used to import Thorntail implementations that are not "core", e.g. microprofile-health, but in the case of microprofile-config, it is not necessary. For WildFly, the implementation org.wildfly.extension.microprofile.config.smallrye is provided so the library shall not be included in the war/ear.