question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Regression: Can't inject beans annotated with `@ConfigProperties`

See original GitHub issue

Describe the bug

Having:

@ConfigProperties(prefix = "server")
public class BulkOfPropertiesConfiguration {
    String url;
    String host;
    String path;
    int port;

    @ConfigProperty(name = "port")
    int repeatedPort;

    @ConfigProperty(name = "url.with.default.found")
    String urlWithDefaultAndConfigFound;
}

And this being in use in:

@Path("/bulk-properties")
public class BulkOfPropertiesResource {

    @Any
    @Inject
    BulkOfPropertiesConfiguration config;

    @GET
    @Path("/url")
    public String getUrl() {
        return config.url;
    }

The app fails to start because says that can’t find BulkOfPropertiesConfiguration:

[ERROR] Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type io.quarkus.qe.properties.bulk.BulkOfPropertiesConfiguration and qualifiers [@Any]
[ERROR]         - java member: io.quarkus.qe.properties.bulk.BulkOfPropertiesResource#config
[ERROR]         - declared on CLASS bean [types=[java.lang.Object, io.quarkus.qe.properties.bulk.BulkOfPropertiesResource], qualifiers=[@Default, @Any], target=io.quarkus.qe.properties.bulk.BulkOfPropertiesResource]
[ERROR]         at io.quarkus.arc.processor.Beans.resolveInjectionPoint(Beans.java:567)
[ERROR]         at io.quarkus.arc.processor.BeanInfo.init(BeanInfo.java:470)
[ERROR]         at io.quarkus.arc.processor.BeanDeployment.init(BeanDeployment.java:256)
[ERROR]         ... 13 more

This is caused by this change: https://github.com/quarkusio/quarkus/pull/19965/commits/6378f80f1c4ff0ad9a50e1cc9944163e2a8eeeeb

I tried to annotate the BulkOfPropertiesConfiguration with @Unremovable and also remove the @Any but nothing helped.

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

  1. git clone https://github.com/Sgitario/quarkus-test-suite
  2. cd quarkus-test-suite
  3. git checkout reproducer_20610
  4. cd properties
  5. mvn clean verify

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
radcortezcommented, Oct 14, 2021
1reaction
Sgitariocommented, Oct 11, 2021

So this is not a bug. Yes, it was working before but it was not intended that way.

The @ConfigProperties qualifier must be used in the injection point when injecting a relevant bean. Of course, you can omit @Inject. Here is the relevant discussion on MP Config: eclipse/microprofile-config#629.

We also have some additional discussions here: #19526

We can certainly make it work again, but I would prefer to make it as it was intended. I think at some point when the MP spec was not final, the qualifier was not required. Since we wrote the implementation before, we never noticed this little detail that change (and there is no TCK test for it either).

Any thoughts?

I’m not sure what exactly is not being done in the intended way. Do you mean that we cannot longer use the @ConfigProperties qualifier and then inject this bean using @Inject?

If so, this is the approach that was used in Quarkus 1.7 (https://quarkus.io/version/1.7/guides/config#using-configproperties). Moreover, if this is not longer supported in Quarkus 2.4 +, we should make a big note in the migration guide about the new usage of the @ConfigProperties as many users might still be using this approach.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chapter 4. Injecting configuration values into your Quarkus ...
ConfigProperties annotation to group configuration properties. The following procedure demonstrates the use of @ConfigProperties annotation on the Quarkus ...
Read more >
java - Why can't I inject one of my PoJo's with Spring's @Value ...
After checking your answer: I think the \@Bean annotation is needed but the \@Qualifier is not. The two managed beans are found without...
Read more >
Contexts and Dependency Injection - Quarkus
This behavior is defined by CDI. But producer methods and fields and observer methods are discovered even if the declaring class is not...
Read more >
spring read environment variable in application properties
A good read explaining the annotations involved can be found here: Spring Java ... Can Enums Be Subclassed to Add New Elements, Why...
Read more >
Documentation - TestNG
Write the business logic of your test and insert TestNG annotations in your code. ... The list of groups you want to run...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found