0

My application.yaml has a map of values stored in a yaml file.

app:
  myMap:
    key1: value1
    key2: value2
    key3: value3

Configuration class:

@Data
@ApplicationScoped
public class AppConfiguration {

    @ConfigProperty(name = "app.myMap")
    private Map<String, String> myMap;
}

This results in the following error:
javax.enterprise.inject.spi.DeploymentException: No config value of type [java.util.Map] exists for: app.myMap

I'm unable to read these values because MicroProfile does not support java.util.Map. I came across this mailing list that suggests a workaround but being rather new to Quarkus, I'm unsure of how to implement this properly. It's also a year old and I'm wondering if there is a better implementation then what was suggested in that mailing list.

user0000001
  • 2,092
  • 2
  • 20
  • 48

1 Answers1

2

Yes, indeed there is a better way now. Quarkus configuration is implemented by SmallRye Config. Unfortunately, it doesn't support Map direct injection directly, but you can use a mapping object like documented here: https://smallrye.io/docs/smallrye-config/main/mapping/mapping.html

Here is an example project: https://github.com/smallrye/smallrye-config/tree/main/examples/mapping

All of this works in Quarkus.

Roberto Cortez
  • 803
  • 4
  • 8