Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default on config pojo should behave the same if set in src/main/resources/application.yaml #13423

Closed
vsevel opened this issue Nov 22, 2020 · 2 comments
Labels
area/config kind/enhancement New feature or request

Comments

@vsevel
Copy link
Contributor

vsevel commented Nov 22, 2020

Description
Assuming the following config object:

@ConfigProperties(prefix = "greeting")
public class MyConfig {
    public String url;
    public String host;
}

and src/main/resources/application.yaml;

greeting:
  url: http://${greeting.host}
  host: myhost

Then the following test will pass:

@QuarkusTest
public class MyTestCase {

    @Inject
    MyConfig config;

    @Test
    public void test() {
        Assertions.assertEquals("http://myhost", config.url);
    }
}

However, if I move host=myhost as a default value, the test won't pass anymore:

greeting:
  url: http://${greeting.host}
  # host: myhost

and:

@ConfigProperties(prefix = "greeting")
public class MyConfig {
    public String url;
    @ConfigProperty(defaultValue = "myhost")
    public String host;
}

then I get the following error at startup:

Caused by: java.util.NoSuchElementException: SRCFG00011: Could not expand value greeting.host in property greeting.url

it is the same behavior if I put the default as the field init: public String host="myhost";

I believe that defaults should be picked up in the code, and applied as if the values were present in the src/main/resources/application.yaml.

@vsevel vsevel added the kind/enhancement New feature or request label Nov 22, 2020
@ghost ghost added the triage/needs-triage label Nov 22, 2020
@radcortez
Copy link
Member

Related with eclipse/microprofile-config#475

@radcortez
Copy link
Member

This can be achieved with @ConfigMapping. Check here: smallrye/smallrye-config@8f40839.

Quarkus @ConfigProperties is now deprecated, so our recommendation is to use @ConfigMapping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/config kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants