spring-data-mongodb
spring-data-mongodb copied to clipboard
Support automatic registration of converters
Hi, i am spring-data-mongo user. I had some inconvenience when registered converters. Is currently manually register converters.
@Bean
fun mongoCustomConversions(): MongoCustomConversions {
val converters = applicationContext.getBeansOfType(Converter::class.java).values
.stream().collect(Collectors.toList())
return MongoCustomConversions(converters)
}
Can I change to automatic registration from manually registration ? If it's not possible, can you tell me why?
How is that supposed to work if a user has multiple Spring Data modules on the class path. We would register all converters in all modules without having a way to distinguish whether a Converter
is intended for Spring Data usage and for which module it should be used.
How is that supposed to work if a user has multiple Spring Data modules on the class path. We would register all converters in all modules without having a way to distinguish whether a
Converter
is intended for Spring Data usage and for which module it should be used.
@mp911de Thank you for reply 😄 So i hope add interface (e.g DocumentFieldConverter).
interface DocumentFieldConverter<S, T> : Converter<S, T>
Then, this is possible as follows.
if (listableBeanFactory != null) {
converters = listableBeanFactory
.getBeansOfType(DocumentFieldConverter.class)
.values()
.stream()
.toList();
} else {
converters = Collections.emptyList();
}
Is this possible?
Thanks for your suggestion. We want to keep the existing mechanism and keep the converter registration as simple as possible. If adding an interface to your converters works in your project, then we encourage you to follow that path and apply that pattern in your project.