@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)
When an application contains metric injection as well as metric producers, it will encounter an ambiguous dependencies error.
Example:
... and in a different class:
(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):