-
Notifications
You must be signed in to change notification settings - Fork 131
Closed
Labels
for: stackoverflowA question that's better suited to stackoverflow.comA question that's better suited to stackoverflow.com
Description
Hey,
I have 3 databases, each having its own DBConfig class, extending the AbstractR2dbcConfiguration.
From the docs: To add custom conversions override the getCustomConversions().
Unfortunally, there is only one global R2dbcCustomConversions Bean instead one for each configuration. This results into only one call of the overriden getCustomConversions() function.
Example:
@Configuration
@EnableR2dbcRepositories(ADBConfig.basePackage, databaseClientRef = ADBConfig.clientName)
class ADBConfig(private val properties: AProperties): AbstractR2dbcConfiguration() {
companion object {
const val basePackage = "org.example.a"
const val clientName = "aDatabaseClient"
const val factory = "aFactory"
}
@Bean(factory)
override fun connectionFactory(): ConnectionFactory {
return H2ConnectionFactory(
H2ConnectionConfiguration.builder()
.url(properties.datasource.jdbcURL)
.username(properties.datasource.userName)
.password(properties.datasource.password)
.build()
)
}
override fun customConverters() = listOf(AWritingConverter(), AReadConverter())
@Bean(clientName)
fun databaseClient(@Qualifier(factory) connectionFactory: ConnectionFactory): DatabaseClient = DatabaseClient.create(connectionFactory)
}
Alternative:
Don't override the getCustomConversions function, but instead the Bean directly with a given name.
@Bean(conversions)
override fun r2dbcCustomConversions()= R2dbcCustomConversions(storeConversions, listOf())
The @Bean R2dbcCustomConversions has now be called by @Qualifier in AbstractR2dbcConfiguration. The qualifier comes from a new attribute with name R2dbcCustomConversionsRefin @EnableR2dbcRepositories.
@Configuration
@EnableR2dbcRepositories(ADBConfig.basePackage, databaseClientRef = ADBConfig.clientName, R2dbcCustomConversionsRef = "aCustomConversions")
class ADBConfig(private val properties: AProperties): AbstractR2dbcConfiguration() {
Metadata
Metadata
Assignees
Labels
for: stackoverflowA question that's better suited to stackoverflow.comA question that's better suited to stackoverflow.com