openwebbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Xavier Dury <kal...@hotmail.com>
Subject RE: CDI and ParameterizedTypes
Date Tue, 19 Mar 2013 08:36:00 GMT
Hi,

I still got the same error with 1.1.8-SNAPSHOT:

javax.enterprise.inject.AmbiguousResolutionException: Ambigious resolution
found beans: 
StringToLongConverter, Name:null, WebBeans Type:MANAGED, API Types:[java.lang.Object,test.StringToLongConverter,test.TypeConverter],
Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]
StringToIntegerConverter, Name:null, WebBeans Type:MANAGED, API Types:[test.TypeConverter,java.lang.Object,test.StringToIntegerConverter],
Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]
	at org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutionExceptionForBeans(InjectionExceptionUtils.java:121)
	at org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutionException(InjectionExceptionUtils.java:111)
	at org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutionException(InjectionExceptionUtils.java:88)
	at org.apache.webbeans.container.InjectionResolver.resolve(InjectionResolver.java:669)
	at org.apache.webbeans.container.InjectionResolver.checkInjectionPoints(InjectionResolver.java:189)
	at org.apache.webbeans.container.BeanManagerImpl.validate(BeanManagerImpl.java:1034)
	at org.apache.openejb.cdi.BeansDeployer.validate(BeansDeployer.java:269)
	at org.apache.openejb.cdi.BeansDeployer.validateInjectionPoints(BeansDeployer.java:222)
	at org.apache.openejb.cdi.OpenEJBLifecycle.startApplication(OpenEJBLifecycle.java:280)
	... 46 more

Xavier
________________________________
> Date: Fri, 15 Mar 2013 15:54:37 +0000 
> From: struberg@yahoo.de 
> Subject: Re: CDI and ParameterizedTypes 
> To: user@openwebbeans.apache.org 
> 
> romain, Xavier, can you please test with the latest 1.1.8-SNAPSHOT? 
> 
> I'll roll a 1.1.8 release this evening. 
> 
> LieGrue, 
> strub 
> 
> 
> ________________________________ 
> From: Romain Manni-Bucau <rmannibucau@gmail.com> 
> To: user@openwebbeans.apache.org 
> Sent: Friday, March 15, 2013 4:17 PM 
> Subject: Re: CDI and ParameterizedTypes 
> 
> Ok 
> 
> guess the fix was not in 
> 
> 
> Romain Manni-Bucau 
> Twitter: @rmannibucau<https://twitter.com/rmannibucau> 
> Blog: http://rmannibucau.wordpress.com/ 
> LinkedIn: http://fr.linkedin.com/in/rmannibucau 
> Github: https://github.com/rmannibucau 
> 
> 
> 
> 2013/3/15 Xavier Dury <kalgon@hotmail.com<mailto:kalgon@hotmail.com>> 
> Hi, 
> 
> I'm using the last version available on maven central repo which is 1.1.7. 
> 
> Xavier 
> 
> ________________________________ 
> > From: rmannibucau@gmail.com<mailto:rmannibucau@gmail.com> 
> > Date: Fri, 15 Mar 2013 15:29:00 +0100 
> > Subject: Re: CDI and ParameterizedTypes 
> > To: user@openwebbeans.apache.org<mailto:user@openwebbeans.apache.org> 
> > 
> > Hi, 
> > 
> > if i didn't miss it you didn't mention your version 
> > 
> > think it should work with 1.1.8 
> > 
> > https://github.com/rmannibucau/cdi-converters was used to work and was 
> > using something 
> > close 
> https://github.com/rmannibucau/cdi-converters/blob/master/src/test/java/com/github/rmannibucau/converter/ConverterTest.java

> > 
> > Romain Manni-Bucau 
> > Twitter: @rmannibucau<https://twitter.com/rmannibucau> 
> > Blog: http://rmannibucau.wordpress.com/ 
> > LinkedIn: http://fr.linkedin.com/in/rmannibucau 
> > Github: https://github.com/rmannibucau 
> > 
> > 
> > 
> > 2013/3/15 Xavier Dury 
> <kalgon@hotmail.com<mailto:kalgon@hotmail.com><mailto:kalgon@hotmail.com<mailto:kalgon@hotmail.com>>>

> > Hi, 
> > 
> > I'm trying to implement a simple type conversion framework in CDI. 
> > Typically, you can either implement the TypeConverter interface or 
> > annotate some methods in your beans: 
> > 
> > public interface TypeConverter<S, T> { 
> > 
> > T convert(S source); 
> > } 
> > 
> > public class StringToIntegerTypeConverter implements 
> > TypeConverter<String, Integer> { ... } 
> > 
> > public class StringToLongTypeConverter implements TypeConverter<String, 
> > Long> { ... } 
> > 
> > public MyConverters { 
> > 
> > @Converts public Integer stringToInteger(String value) { ... } 
> > @Converts public Long stringToLong(String value) { ... } 
> > } 
> > 
> > A specific Extension "bridges" the annotated methods to a full 
> > TypeConverter (a custom Bean<?> is registered with an API types of 
> > ParameterizedTypeImpl(rawType = TypeConverter.class, ownerType = null, 
> > actualTypeArguments = [method.getGenericParameterType[0], 
> > method.getGenericReturnType])). 
> > 
> > Then a TypeConversionService is responsible to find the adequate 
> > Converter through the BeanManager and call it with the provided object 
> > to be converted. 
> > 
> > public class TypeConversionService { 
> > 
> > public <T> T convert(Class<T> targetType, Object source) { ... } 
> > public <T> T convert(TypeLiteral<T> targetTypeLiteral, Object source)

> { ... } 
> > } 
> > 
> > My problem is the following: as soon as 2 or more TypeConverters are 
> > present in the module (let's say StringToIntegerTypeConverter and 
> > StringToLongTypeConverter), an ambiguous dependency exception is 
> > thrown. 
> > 
> > For example: 
> > 
> > public class MyBean { 
> > 
> > @Inject TypeConverter<String, Integer> stringToIntegerTypeConverter; 
> > @Inject TypeConverter<String, Long> stringToLongTypeConverter; 
> > 
> > // won't work 
> > } 
> > 
> > If I delete one of the TypeConverter classes (StringToLongTypeConverter 
> > for example), the remaining TypeConverter 
> > (StringToIntegerTypeConverter) is injected at the 2 injection points 
> > (stringToIntegerTypeConverter=ok and stringToLongTypeConverter=!ok). 
> > 
> > Is it possible with CDI to have such a scenario without using 
> > additional qualifiers to qualify each converter and only rely on the 
> > (parameterized) type information to tell them apart? 
> > 
> > I've seen some discussions on StackOverflow saying the TypeConverter 
> > should belong to the Dependent scope but it didn't work for me. 
> > 
> > Thanks, 
> > 
> > Xavier 
> > 
> 
> 
> 		 	   		  
Mime
View raw message