Know that @ConditionalOnMissingBean
is there for us to override the whole bean, and eventually could provide any custom converters.
How about provide similar mechanism of WebFluxConfigurer
, so just to provide the implementation of org.springframework.core.convert.converter.Converter
would suffice.
https://github.com/spring-projects/spring-boot/blob/9bf9442ec9ff7c38b06ac552de0d0dc23297f364/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/r2dbc/R2dbcDataAutoConfiguration.java#L106
@Bean
@ConditionalOnMissingBean
public R2dbcCustomConversions r2dbcCustomConversions() {
List<Object> converters = new ArrayList<>(this.dialect.getConverters());
converters.addAll(R2dbcCustomConversions.STORE_CONVERTERS);
return new R2dbcCustomConversions(
CustomConversions.StoreConversions.of(this.dialect.getSimpleTypeHolder(), converters),
Collections.emptyList());
}
Comment From: wilkinsona
Thanks for the suggestion, but I'm not sure exactly what you're looking for here. If you're proposing changes to the R2dbcCustomConversions
API, it's part of Spring Data R2DBC and an issue would have to be opened over there. If you're proposing changes to Spring Boot, can you please elaborate? Perhaps you can share an example of what you'd like to be able to do.
Comment From: junyongz
Maybe XxxConfigurer is not a good example.
Elaborate again.
@Bean
@ConditionalOnMissingBean
public R2dbcCustomConversions r2dbcCustomConversions(ObjectProvider<UserConvertersProvider> convertersProvider) {
List<Object> converters = new ArrayList<>(this.dialect.getConverters());
converters.addAll(R2dbcCustomConversions.STORE_CONVERTERS);
return new R2dbcCustomConversions(
CustomConversions.StoreConversions.of(this.dialect.getSimpleTypeHolder(), converters),
convertersProvider.getIfAvailable(() -> Collections.emptyList()).converters());
}
Then, in user codes, just to provide the @Bean
of UserConvertersProvider
to provide the actual converters through converters()
method
Actually, I am using Postgresql database, and one of the field of the table is JSON field, it is mapped to a POJO, so I need the converters to be registered, and what I found so far is to override R2dbcCustomConversions @Bean