When I create configuration properties with kotlin delegation pattern cannot be bind as bean.
Properties code
@ConstructorBinding
@ConfigurationProperties
class MapPropertiesWithDelegation(val properties: Map<String, String>) : Map<String, String> by properties
Error message
```plain text
Caused by: java.lang.NoSuchMethodException: org.springframework.boot.context.properties.KotlinConfigurationPropertiesTests$MapPropertiesWithDelegation.
<b>Test code</b>
```kotlin
@Test
fun `map property with delegation should access as map interface`() {
load(ConstructorParameterConfiguration::class.java, "properties.name:name", "properties.value:value")
val bean = this.context.getBean(MapPropertiesWithDelegation::class.java)
assertThat(bean["name"]).isEqualTo("name")
assertThat(bean["value"]).isEqualTo("value")
}
private fun load(configuration: Class<*>, vararg inlinedProperties: String): AnnotationConfigApplicationContext? {
return load(arrayOf(configuration), *inlinedProperties)
}
private fun load(configuration: Array<Class<*>>, vararg inlinedProperties: String): AnnotationConfigApplicationContext? {
context.register(*configuration)
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(context, *inlinedProperties)
context.refresh()
return context
}
I Guess...
private AggregateBinder<?> getAggregateBinder(Bindable<?> target, Context context) {
Class<?> resolvedType = target.getType().resolve(Object.class);
if (Map.class.isAssignableFrom(resolvedType)) {
return new MapBinder(context);
}
if (Collection.class.isAssignableFrom(resolvedType)) {
return new CollectionBinder(context);
}
if (target.getType().isArray()) {
return new ArrayBinder(context);
}
return null;
}
This method of Binder Class seems to recognize the configuration properties class as Map.
Comment From: mbhave
@hyeonisism I'm finding it hard to follow what the issue is from a few code snippets. Can you provide a minimal sample that we can run to reproduce the issue?
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.