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

Ambiguous dependencies error when using injection and producers in the same app #107

Open
jmartisk opened this issue Apr 24, 2019 · 1 comment
Labels
bug Something isn't working

Comments

@jmartisk
Copy link
Member

jmartisk commented Apr 24, 2019

When an application contains metric injection as well as metric producers, it will encounter an ambiguous dependencies error.

Example:

    @Inject
    @Metric(name = "injected-counter", absolute = true)
    private Counter counter;

... and in a different class:

    @Produces
    @Metric(name = "producerfield-counter", absolute = true, description = "Counter from producer field.")
    Counter counter = new CounterImpl();

(The injection point and the producer field have to be for the same metric type, in this case it is counter)
If the application contains just one of these two things, it will work fine.

the error looks like this (this is from Thorntail):

019-04-24 12:53:21,376 ERROR [stderr] (main)     Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001409: Ambiguous dependencies for type Counter with qualifiers @Default
2019-04-24 12:53:21,376 ERROR [stderr] (main)   at injection point [BackedAnnotatedField] @Inject @Metric private com.example.metrics.InjectResource.counter
2019-04-24 12:53:21,377 ERROR [stderr] (main)   at com.example.metrics.InjectResource.counter(InjectResource.java:0)
2019-04-24 12:53:21,377 ERROR [stderr] (main)   Possible dependencies: 
2019-04-24 12:53:21,377 ERROR [stderr] (main)   - Producer Method [Counter] with qualifiers [@Any @Default] declared as [[UnbackedAnnotatedMethod] @Produces io.smallrye.metrics.MetricProducer.getCounter(InjectionPoint)],
2019-04-24 12:53:21,377 ERROR [stderr] (main)   - Producer Method [Counter] with qualifiers [@Any @Default] declared as [[BackedAnnotatedMethod] @Produces @Metric com.example.metrics.ProducersMethodsResource.counter()],
2019-04-24 12:53:21,377 ERROR [stderr] (main)   - Producer Field [Counter] with qualifiers [@Any @Default] declared as [[BackedAnnotatedField] @Produces @Metric com.example.metrics.ProducersFieldsResource.counter]
2019-04-24 12:53:21,377 ERROR [stderr] (main) "}}
2019-04-24 12:53:21,377 ERROR [stderr] (main) 	at org.wildfly.swarm.container.runtime.RuntimeDeployer.deploy(RuntimeDeployer.java:296)

@jmartisk jmartisk added the bug Something isn't working label Apr 24, 2019
@eldarj
Copy link

eldarj commented May 9, 2022

Any updates on this issue? I'm encountering the same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants