Upgrading-Problems: mp-config 1.4 to 2.0

41 views
Skip to first unread message

Markus Grill

unread,
May 31, 2021, 1:25:16 PMMay 31
to MicroProfile
Hi everyone, 

I have a problem with my converters after upgrading from mp-config 1.4 to 2.0
I hope this is the right place to ask...

Here's a simplified code which works perfectly with 1.4:

package org;
class MyExample {
  ...
  @Inject
  @ConfigProperty
  MyObject myObj;
  ...
}

class MyObjectConverter implements Converter<MyObject> {...}

Now with 2.0 i get the error-message "No Config Value exists for required property org.MyExample.myObj". After some trial and error the following code fixed that problem

class MyConfigSource implements ConfigSource {
   ...
   public Set<String> getPropertyNames() {
      return Set.of("org.demo.Demo.myObj");
   ...
}

But that doesn't make sense to me. Did I miss something in version 2.0?

Thank you
Markus

Roberto Cortez

unread,
May 31, 2021, 3:58:42 PMMay 31
to microp...@googlegroups.com
Hi Markus,

Thanks for reaching out. 

There has been a few changes regarding Converters (and values):

Please note that `getPropertyNames` became an abstract method, so you now need to provide an implementation:

That does not explain the observed error. I recommend to check with the MP Config implementation that you are using.

Cheers,
Roberto

--
You received this message because you are subscribed to the Google Groups "MicroProfile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to microprofile...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/microprofile/1f814367-bd8c-45c9-992c-125a7d3c7dffn%40googlegroups.com.

Markus Grill

unread,
Jun 1, 2021, 5:37:11 AMJun 1
to MicroProfile
Hi Roberto,

Thank you for your advice.

I use the current JBoss-Wildfly 23.0.2. The smallrye project is used internally for the mp-implementation. I will take a closer look at it here and then, if necessary, contact the Wildfly forum.

Greetings
Markus

Roberto Cortez

unread,
Jun 1, 2021, 8:37:36 AMJun 1
to microp...@googlegroups.com
I’m also one of the maintainers of SR Config, so feel free to reach out :)

Cheers,
Roberto

Markus Grill

unread,
Jun 2, 2021, 3:38:21 AMJun 2
to MicroProfile
Hi Roberto,

I was now able to isolate the problem. It is because the implicit default value in the @ConfigProperty annotation no longer works. It would work again with the following setting
@ConfigProperty(defaultValue = "")

Maybe I have used the converter for purposes other than intended. Here is a simplified example

microprofile-config.properties
sys_1.p1 = x1
sys_1.p2 = y1
sys_1.p3 = z1

sys_2.p1 = x2
sys_2.p2 = y2
sys_2.p3 = z2
...
sys_n.p1 = xn
sys_n.p2 = yn
sys_n.p3 = zn

@Inject
@ConfigProperty
MyObject myObj;

myObj.get("sys_1").getP1();
myObj.get("sys_2").getP1();
myObj.get("sys_n").getP1();

The value in the ConfigProperty is irrelevant here. I should probably use the converter in the following form

@Inject
@ConfigProperty(name="mo")
MyObject myObj;

microprofile-config.properties
mo = sys_1.p1=x1, sys_1.p2=y1, sys_1.p3=z1 | sys_2.p1=x2, sys_2.p2=y2, sys_2.p3=z2 | sys_n.p1=xn, sys_n.p2=yn, sys_n.p3=zn

Unfortunately, this is not a clear representation, especially if the real values are entered. And furthermore, I no longer have the option of overwriting individual values, e.g. sys_2.p1 = q
Maybe it's better if I work with a CDI producer here.

Greetings
Markus

Roberto Cortez

unread,
Jun 2, 2021, 5:37:29 AMJun 2
to microp...@googlegroups.com
It seems you are trying to represent a Map. 

In SR Config, we have ways to map Maps directly. This week we added direct map injection (not released yet), but we can usually accomplish that using a ConfigMapping. Take a look here:

This is the equivalent to MP @ConfigProperties, but enhanced with more features.

Hope it helps!

Cheers,
Roberto

Emily Jiang

unread,
Jun 7, 2021, 1:52:39 PMJun 7
to MicroProfile
Hi Markus,

Just add another comment: this change was documented in the MP Config 2.0 release note. You can find other incompatible changes from the release note, which should help with explaining the migration path.

Thanks
Emily

Markus Grill

unread,
Jun 14, 2021, 12:10:05 PMJun 14
to MicroProfile
Hi,

after a few tests I have now come to the result that I should work with the new @ConfigProperties (prefix = "") annotation for the simpler cases. In the more complex case, the configuration is now made available via a CDI producer with corresponding bean validation.

Roberto, thank you for your reference to the SR-Config. However, I would only have gone into this variant if necessary, since we only refer to the microprofile API in the maven-pom and want to leave the implementation to the application server.

Emily, the release notes match what I've already learned.

Thank you
Markus

Emily Jiang

unread,
Jun 14, 2021, 2:17:01 PMJun 14
to MicroProfile
Thank you Markus for the update!
Thanks
Emily
Reply all
Reply to author
Forward
0 new messages