You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Error message showing the listOfString and listOfListOfString beans being seen as the same type after erasure:
java.lang.AssertionError:
Expecting code not to raise a throwable but caught
"org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'java.util.List' available: expected single matching bean but found 2: listOfString,listOfListOfString
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.java:1310)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveBean(DefaultListableBeanFactory.java:484)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:339)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:332)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1192)
at org.sdkotlin.springdemo.SpringGetBeanNestedGenericIT.test_getBean_with_nested_generic$lambda$0(SpringGetBeanNestedGenericIT.kt:37)
at org.assertj.core.api.ThrowableAssert.catchThrowable(ThrowableAssert.java:63)
at org.assertj.core.api.NotThrownAssert.isThrownBy(NotThrownAssert.java:43)
at org.sdkotlin.springdemo.SpringGetBeanNestedGenericIT.test getBean with nested generic(SpringGetBeanNestedGenericIT.kt:30)
If I remove the listOfListOfString bean from the configuration, the test passes.
I can inject both beans just fine, i.e. the following passes:
Added #31444 to request ParameterizedTypeReference overloads to the Java BeanFactory.getBean methods, which would presumably streamline the implementation of the Kotlin extensions.
You can get the behavior you want with applicationContext.getBeanProvider<List<String>>().getObject() or getIfAvailable() since we are leveraging the underlying ResolvableType based capabilities. That said, we could maybe potentially leverage that instead of getBean(T::class.java) for the implementation of the inline fun <reified T : Any> BeanFactory.getBean(): T Kotlin extension. I will give it more thoughts and let you know.
With 6.1.0-RC1 (and likely prior), the following test of the
BeanFactory.getBean
extension fails, presumably due to erasure:Error message showing the
listOfString
andlistOfListOfString
beans being seen as the same type after erasure:If I remove the
listOfListOfString
bean from the configuration, the test passes.I can inject both beans just fine, i.e. the following passes:
I notice the
BeanFactory.getBeanProvider
extension uses the super type token approach. Perhaps this could be used as well forgetBean
to address this issue:If I import that version of the extension instead, the test passes with the
listOfListOfString
bean in the configuration.The text was updated successfully, but these errors were encountered: