You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@openwebbeans.apache.org by Krzysztof Śmigrodzki <ks...@gmail.com> on 2025/02/03 11:59:40 UTC

AmbiguousResolutionException thrown by OWB for Smallrye @ConfigProperty in JavaSE.

I've tried to use Microprofile Config in Java SE to inject configuration,
but I was greeted by the following exception:


Exception in thread "main"
org.apache.webbeans.exception.WebBeansDeploymentException:
jakarta.enterprise.inject.AmbiguousResolutionException: There is more than
one Bean with type java.lang.String Qualifiers:
[@org.eclipse.microprofile.config.inject.ConfigProperty(name="test.property",
defaultValue="org.eclipse.microprofile.config.configproperty.unconfigureddvalue")]
for injection into Field Injection Point, field name :  testProperty, Bean
Owner : [OurBean, WebBeansType:MANAGED, Name:null, API
Types:[java.lang.Object,me.noip.ksmigrod.spikes.cdiconfig.OurBean],
Qualifiers:[jakarta.enterprise.inject.Default,jakarta.enterprise.inject.Any]]
found beans:
String, WebBeansType:PRODUCERMETHOD, Name:null, API
Types:[java.io.Serializable,java.lang.CharSequence,java.lang.constant.ConstantDesc,java.lang.Comparable<String>,java.lang.String,java.lang.Object,java.lang.constant.Constable],
Qualifiers:[jakarta.enterprise.inject.Any,org.eclipse.microprofile.config.inject.ConfigProperty],
Producer Method: protected java.lang.String
io.smallrye.config.inject.ConfigProducer.produceStringConfigProperty(jakarta.enterprise.inject.spi.InjectionPoint)
from
jar:file:/home/ksm/IdeaProjects/spikes/cdi-config/target/lib/smallrye-config-3.11.1.jar!/io/smallrye/config/inject/ConfigProducer.class
String, WebBeansType:PRODUCERMETHOD, Name:null, API
Types:[java.io.Serializable,java.lang.CharSequence,java.lang.constant.ConstantDesc,java.lang.Comparable<String>,java.lang.String,java.lang.Object,java.lang.constant.Constable],
Qualifiers:[jakarta.enterprise.inject.Any,org.eclipse.microprofile.config.inject.ConfigProperty],
Producer Method: protected java.lang.String
io.smallrye.config.inject.ConfigProducer.produceStringConfigProperty(jakarta.enterprise.inject.spi.InjectionPoint)
from
jar:file:/home/ksm/IdeaProjects/spikes/cdi-config/target/lib/smallrye-config-3.11.1.jar!/io/smallrye/config/inject/ConfigProducer.class

This message refers to the same metod of the same bean twice, which
suggests a bug.

I've made a minimal example of that error, and published it on github,
README file for this project contains full stacktrace.
https://github.com/ksmigrod/cdi-config/

Project runs with Weld. The project builds with OpenWebBeans, but fails at
runtime with AmbiguousResolutionException.

Is it a bug in OWB, or is there something wrong with my code?

Regards,
Krzysztof Śmigrodzki

Re: AmbiguousResolutionException thrown by OWB for Smallrye @ConfigProperty in JavaSE.

Posted by Krzysztof Śmigrodzki <ks...@gmail.com>.
Thanks.

To keep it complete: missing ingredient was file:
`META-INF/openwebbeans/openwebbeans.properties` with the following content:

configuration.ordinal=101
org.apache.webbeans.scanExclusionPaths=smallrye-config-3.11.1.jar

This allowed example project to run.

Krzysztof Śmigrodzki




pon., 3 lut 2025 o 13:26 Romain Manni-Bucau <rm...@gmail.com>
napisał(a):

> Hi,
>
> Yes, maybe a bug in smallrye.
>
> In the setup you deploy you scan smallrye-config so configproducer and the
> extension in this jar adds configproducer with a custom identifier so owb
> doesn't deduplicate the scanned and programmatic beans since they are
> different for CDI.
> One option is to exclude smallrye-config from the scanning or veto one of
> the two beans with a custom extension.
>
> Ideally smallrye should only add the bean if not found during the startup
> IMHO as most CDI extensions do.
>
> Romain Manni-Bucau
> @rmannibucau <https://x.com/rmannibucau> | .NET Blog
> <https://dotnetbirdie.github.io/> | Blog <https://rmannibucau.github.io/> |
> Old Blog <http://rmannibucau.wordpress.com> | Github
> <https://github.com/rmannibucau> | LinkedIn
> <https://www.linkedin.com/in/rmannibucau> | Book
> <https://www.packtpub.com/en-us/product/java-ee-8-high-performance-9781788473064>
>
>
> Le lun. 3 févr. 2025 à 12:59, Krzysztof Śmigrodzki <ks...@gmail.com> a
> écrit :
>
>> I've tried to use Microprofile Config in Java SE to inject configuration,
>> but I was greeted by the following exception:
>>
>>
>> Exception in thread "main"
>> org.apache.webbeans.exception.WebBeansDeploymentException:
>> jakarta.enterprise.inject.AmbiguousResolutionException: There is more than
>> one Bean with type java.lang.String Qualifiers:
>> [@org.eclipse.microprofile.config.inject.ConfigProperty(name="test.property",
>> defaultValue="org.eclipse.microprofile.config.configproperty.unconfigureddvalue")]
>> for injection into Field Injection Point, field name :  testProperty,
>> Bean Owner : [OurBean, WebBeansType:MANAGED, Name:null, API
>> Types:[java.lang.Object,me.noip.ksmigrod.spikes.cdiconfig.OurBean],
>> Qualifiers:[jakarta.enterprise.inject.Default,jakarta.enterprise.inject.Any]]
>> found beans:
>> String, WebBeansType:PRODUCERMETHOD, Name:null, API
>> Types:[java.io.Serializable,java.lang.CharSequence,java.lang.constant.ConstantDesc,java.lang.Comparable<String>,java.lang.String,java.lang.Object,java.lang.constant.Constable],
>> Qualifiers:[jakarta.enterprise.inject.Any,org.eclipse.microprofile.config.inject.ConfigProperty],
>> Producer Method: protected java.lang.String
>> io.smallrye.config.inject.ConfigProducer.produceStringConfigProperty(jakarta.enterprise.inject.spi.InjectionPoint)
>> from
>> jar:file:/home/ksm/IdeaProjects/spikes/cdi-config/target/lib/smallrye-config-3.11.1.jar!/io/smallrye/config/inject/ConfigProducer.class
>> String, WebBeansType:PRODUCERMETHOD, Name:null, API
>> Types:[java.io.Serializable,java.lang.CharSequence,java.lang.constant.ConstantDesc,java.lang.Comparable<String>,java.lang.String,java.lang.Object,java.lang.constant.Constable],
>> Qualifiers:[jakarta.enterprise.inject.Any,org.eclipse.microprofile.config.inject.ConfigProperty],
>> Producer Method: protected java.lang.String
>> io.smallrye.config.inject.ConfigProducer.produceStringConfigProperty(jakarta.enterprise.inject.spi.InjectionPoint)
>> from
>> jar:file:/home/ksm/IdeaProjects/spikes/cdi-config/target/lib/smallrye-config-3.11.1.jar!/io/smallrye/config/inject/ConfigProducer.class
>>
>> This message refers to the same metod of the same bean twice, which
>> suggests a bug.
>>
>> I've made a minimal example of that error, and published it on github,
>> README file for this project contains full stacktrace.
>> https://github.com/ksmigrod/cdi-config/
>>
>> Project runs with Weld. The project builds with OpenWebBeans, but fails
>> at runtime with AmbiguousResolutionException.
>>
>> Is it a bug in OWB, or is there something wrong with my code?
>>
>> Regards,
>> Krzysztof Śmigrodzki
>>
>

Re: AmbiguousResolutionException thrown by OWB for Smallrye @ConfigProperty in JavaSE.

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi,

Yes, maybe a bug in smallrye.

In the setup you deploy you scan smallrye-config so configproducer and the
extension in this jar adds configproducer with a custom identifier so owb
doesn't deduplicate the scanned and programmatic beans since they are
different for CDI.
One option is to exclude smallrye-config from the scanning or veto one of
the two beans with a custom extension.

Ideally smallrye should only add the bean if not found during the startup
IMHO as most CDI extensions do.

Romain Manni-Bucau
@rmannibucau <https://x.com/rmannibucau> | .NET Blog
<https://dotnetbirdie.github.io/> | Blog <https://rmannibucau.github.io/> | Old
Blog <http://rmannibucau.wordpress.com> | Github
<https://github.com/rmannibucau> | LinkedIn
<https://www.linkedin.com/in/rmannibucau> | Book
<https://www.packtpub.com/en-us/product/java-ee-8-high-performance-9781788473064>


Le lun. 3 févr. 2025 à 12:59, Krzysztof Śmigrodzki <ks...@gmail.com> a
écrit :

> I've tried to use Microprofile Config in Java SE to inject configuration,
> but I was greeted by the following exception:
>
>
> Exception in thread "main"
> org.apache.webbeans.exception.WebBeansDeploymentException:
> jakarta.enterprise.inject.AmbiguousResolutionException: There is more than
> one Bean with type java.lang.String Qualifiers:
> [@org.eclipse.microprofile.config.inject.ConfigProperty(name="test.property",
> defaultValue="org.eclipse.microprofile.config.configproperty.unconfigureddvalue")]
> for injection into Field Injection Point, field name :  testProperty, Bean
> Owner : [OurBean, WebBeansType:MANAGED, Name:null, API
> Types:[java.lang.Object,me.noip.ksmigrod.spikes.cdiconfig.OurBean],
> Qualifiers:[jakarta.enterprise.inject.Default,jakarta.enterprise.inject.Any]]
> found beans:
> String, WebBeansType:PRODUCERMETHOD, Name:null, API
> Types:[java.io.Serializable,java.lang.CharSequence,java.lang.constant.ConstantDesc,java.lang.Comparable<String>,java.lang.String,java.lang.Object,java.lang.constant.Constable],
> Qualifiers:[jakarta.enterprise.inject.Any,org.eclipse.microprofile.config.inject.ConfigProperty],
> Producer Method: protected java.lang.String
> io.smallrye.config.inject.ConfigProducer.produceStringConfigProperty(jakarta.enterprise.inject.spi.InjectionPoint)
> from
> jar:file:/home/ksm/IdeaProjects/spikes/cdi-config/target/lib/smallrye-config-3.11.1.jar!/io/smallrye/config/inject/ConfigProducer.class
> String, WebBeansType:PRODUCERMETHOD, Name:null, API
> Types:[java.io.Serializable,java.lang.CharSequence,java.lang.constant.ConstantDesc,java.lang.Comparable<String>,java.lang.String,java.lang.Object,java.lang.constant.Constable],
> Qualifiers:[jakarta.enterprise.inject.Any,org.eclipse.microprofile.config.inject.ConfigProperty],
> Producer Method: protected java.lang.String
> io.smallrye.config.inject.ConfigProducer.produceStringConfigProperty(jakarta.enterprise.inject.spi.InjectionPoint)
> from
> jar:file:/home/ksm/IdeaProjects/spikes/cdi-config/target/lib/smallrye-config-3.11.1.jar!/io/smallrye/config/inject/ConfigProducer.class
>
> This message refers to the same metod of the same bean twice, which
> suggests a bug.
>
> I've made a minimal example of that error, and published it on github,
> README file for this project contains full stacktrace.
> https://github.com/ksmigrod/cdi-config/
>
> Project runs with Weld. The project builds with OpenWebBeans, but fails at
> runtime with AmbiguousResolutionException.
>
> Is it a bug in OWB, or is there something wrong with my code?
>
> Regards,
> Krzysztof Śmigrodzki
>