I'm using Spring Boot, jOOQ and R2DBC.
By following this post I've created a DSLContext bean:
@Configuration
open class JooqConfig(private val cfi: ConnectionFactory) {
@Bean
open fun jooqContext(): DSLContext {
return DSL.using(cfi).dsl();
}
}
application.yml
spring:
r2dbc:
url: r2dbc:h2:mem:///~/db/testdb
username: sa
password: password
I've then created a Repository.
@Repository
@Transactional
open class JooqUserRepository(private val dslContext: DSLContext) {
suspend fun getUser(): Record {
return dslContext.select() // dslContext is null
.from(USER_MODEL)
.awaitFirst()
}
}
This throws an exception:
Cannot invoke "org.jooq.DSLContext.select(org.jooq.SelectFieldOrAsterisk[])" because "this.dslContext" is null
java.lang.NullPointerException: Cannot invoke "org.jooq.DSLContext.select(org.jooq.SelectFieldOrAsterisk[])" because "this.dslContext" is null
I've checked my config and DSL.using(cfi).dsl()
is definitely returning an object.
What am I missing here? I'm struggling to find documentation on how to get this setup with Spring Boot and R2DBC.
Update
Main class
@SpringBootApplication
open class BrewServerApplication
fun main(args: Array<String>) {
SpringApplication.run(BrewServerApplication::class.java, *args)
}
I guess that the problem is next one:
If you will remove
@Transactional
fromJooqUserRepository
thedslContext
Bean in going to be injected and will not benull
:And also the problem here is that the methods are
final
by default inKotlin
, soSpring
is unable to create proxy for the class.As a fix you have to rewrite:
TO