How to use infobip-spring-data-querydsl?

83 Views Asked by At

I'm working on a new Spring Boot 3 application that has a ClientService linked to a ClientRepository which is a simple R2dbcRepository. I would like to extend my repository to perform more complex requests to a PostgreSQL database but also avoid writing plain SQL requests in @Query annotations. I found this lib: infobip-spring-data-query-dsl which has a R2DBC module. I changed my ClientRepository to implement QuerydslR2dbcRepository but then the application wouldn't start:

Parameter 0 of method querydslSqlConfiguration in com.infobip.spring.data.r2dbc.R2dbcConfiguration required a bean of type 'com.querydsl.sql.SQLTemplates' that could not be found.

I tried following the examples from the GitHub repo and declared a SQLTemplates Bean using Flyway like so:

    @Bean
    fun sqlTemplates(flyway: Flyway): SQLTemplates {
        val jdbcConnectionFactory = JdbcConnectionFactory(
            flyway.configuration.dataSource,
            flyway.configuration,
            null
        )
        val sqlTemplatesRegistry = SQLTemplatesRegistry()
        val metaData = jdbcConnectionFactory.openConnection().metaData
        val templates = sqlTemplatesRegistry.getTemplates(metaData)
        return if (templates is SQLServerTemplates && metaData.databaseMajorVersion > 11) {
            SQLServer2012Templates()
        } else templates
    }

Now I get the following error indicating that Q-classes are not generated:

org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'clientService': 
Unsatisfied dependency expressed through field 'clientRepository': 
Error creating bean with name 'clientRepository' defined in com.ttt.core.repositories.ClientRepository defined in @EnableR2dbcRepositories declared on QuerydslR2dbcRepositoriesAutoConfigureRegistrar.EnableR2dbcRepositoriesConfiguration: 
Unable to load class com.ttt.core.entities.QClient

I have no idea where to start, I can hardly find any documentation and cannot get the examples to work. Could anyone using this lib help me get started? Thank you!

Here are my dependencies as declared in my build.gradle file:

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-r2dbc'
    implementation 'org.springframework.boot:spring-boot-starter-webflux'
    implementation 'com.fasterxml.jackson.module:jackson-module-kotlin'
    implementation 'io.projectreactor.kotlin:reactor-kotlin-extensions'
    implementation 'org.jetbrains.kotlin:kotlin-reflect'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-reactor'
    runtimeOnly 'org.postgresql:postgresql'
    runtimeOnly 'org.postgresql:r2dbc-postgresql'
    implementation 'com.infobip:infobip-spring-data-r2dbc-querydsl-boot-starter:8.1.2'
    implementation 'org.flywaydb:flyway-core:9.21.0'
    implementation 'org.flywaydb:flyway-sqlserver:9.21.0'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'io.projectreactor:reactor-test'
}
0

There are 0 best solutions below