0

I am creating a spring boot application, and using doma for O/R mapper.

I could not start application because repositoryimpl can not find dao class , but i can see them in the build/classes . so build is successful but the application fail to start.

How can I fix it?

Package
enter image description here

Build class
enter image description here

dao class

package com.event.app.backend.infrastructure.dao

import com.event.app.backend.infrastructure.table.EventsTableRecord
import org.seasar.doma.Dao
import org.seasar.doma.Select
import org.seasar.doma.Update
import org.seasar.doma.boot.ConfigAutowireable

@ConfigAutowireable
@Dao
interface EventDao {

  @Select
  fun getEvents():List<EventsTableRecord>

  @Select
  fun getEventById(eventId:String):EventsTableRecord

  @Update(sqlFile = true)
  fun updateTicketCnt(eventId:String,bookTicketCnt:Int):Int

  @Update(sqlFile = true)
  fun subtractTicketCnt(eventId:String,subtractCount:Int):Int
}

impl class

@Repository
class EventRepositoryImpl(
  private val eventDao: EventDao,
  private val userDao: UserDao,
) : EventRepository {

  /**
   * get Events
   */
  override fun getEvents(): List<Event> {
   // return convertToEvent(eventDao.getEvents())
    return listOf(Event(
      name = "event1",
      description =  "description1",
      date = LocalDate.now(),
      availableTickets = 1
    ))
  }

-omit the  details-

build.gradle

buildscript{
    repositories{
        mavenCentral()
    }
    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10")
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.6.2")
    }
}
plugins{
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
}

apply plugin: "java"
apply plugin: "kotlin"

repositories {
    mavenCentral()
}

// テンポラリディレクトリのパスを定義する
ext.domaResourcesDir = "${buildDir}/tmp/doma-resources"

// domaが注釈処理で参照するリソースをテンポラリディレクトリに抽出
task extractDomaResources(type: Copy)  {
    dependsOn processResources

    from processResources.destinationDir
    include 'doma.compile.config'
    include 'META-INF/**/*.sql'
    include 'META-INF/**/*.script'
    into domaResourcesDir
}

// テンポラリディレクトリ内のリソースをcompileJavaタスクの出力先ディレクトリにコピーする
task copyDomaResources(type: Copy, dependsOn: extractDomaResources)  {
    dependsOn extractDomaResources
    from domaResourcesDir
    into compileJava.destinationDir
}

compileJava {
     // 上述のタスクに依存させる
      dependsOn copyDomaResources
    // テンポラリディレクトリをcompileJavaタスクの入力ディレクトリに設定する
    inputs.dir domaResourcesDir
    options.encoding = 'UTF-8'
}

compileTestJava {
    options.encoding = 'UTF-8'
    // テストの実行時は注釈処理を無効にする
    options.compilerArgs = ['-proc:none']
}

dependencies {

    // spring starter web
    implementation ("org.springframework.boot:spring-boot-starter-web")

    // doma sprig boot starter
    implementation ("org.seasar.doma.boot:doma-spring-boot-starter:1.5.0")
    // domaの注釈処理を実行することを示す
    annotationProcessor 'org.seasar.doma:doma:2.29.0'
    // domaへの依存を示す
    implementation 'org.seasar.doma:doma:2.29.0'
}

repositories {
    mavenCentral()
}


dependencyManagement{
    imports{
        mavenBom "org.springframework.boot:spring-boot-dependencies:2.6.2"
    }
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8

    kotlinOptions {
        jvmTarget = '11'
    }
}

added UserDao.kt

package com.event.app.backend.infrastructure.dao

import com.event.app.backend.infrastructure.table.UsersTicketsTableRecord
import org.seasar.doma.Dao
import org.seasar.doma.Insert
import org.seasar.doma.Select
import org.seasar.doma.boot.ConfigAutowireable

@ConfigAutowireable
@Dao
interface UserDao {

  @Insert
  fun insertUsersTickets(usersTicketsTableRecord: UsersTicketsTableRecord):Result<UsersTicketsTableRecord>

  @Select
  fun getTicketCntByEventUserId(eventId:String,userId:String):Int
}

iioiia
  • 15
  • 5

2 Answers2

0

In the case of Spring Boot, you'd need to define the Dao's in a BeanConfig. I guess it's something similiar in this case.

import org.jdbi.v3.core.Jdbi;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import se.xxx.dao.*;

@Configuration
public class BeanConfig {

    @Bean
    public SwingPositionDao swingPositionDao(@Qualifier("jdbi.manager") Jdbi jdbi) {
        return jdbi.onDemand(SwingPositionDao.class);
    }
}
Kim Kakan Andersson
  • 548
  • 1
  • 5
  • 15
  • @Configuautowireable plays the role of dependency injection , so it might be other reason , thanks – iioiia Jan 15 '22 at 13:07
0

You'd need to use kapt instead of annotationProcessor in build.gradle when you use Doma with Kotlin. The code generated by kapt can be found under build/generated/source/kapt.

The following sample repository may be helpful. https://github.com/domaframework/kotlin-sample

  • thanks, I added kapt setting apply plugin: 'kotlin-kapt' and dependencies {kapt("org.seasar.doma:doma-processor:2.51.0") // domaへの依存を示す implementation("org.seasar.doma:doma-kotlin:2.51.0") } but it says the same thing – iioiia Jan 20 '22 at 00:00
  • I think I need to change around copyDomaResource , compileJava.destinationDirectory → compileKotlin.destinationDirectory but , there is no method "destinationDirectory" for compileKotlin – iioiia Jan 20 '22 at 00:16
  • What version of Gradle are you using? If you use the org.seasar.doma.compile plugin as shown in the linked code, the copyDomaResource task is not necessary. – Toshihiro Nakamura Jan 22 '22 at 01:23
  • thanks toshihiro, i could start Application using org.seasar.doma.compile plugin , and I could call sql. but when it comes to calling @Insert method , i have this error. I have no idea why only Insert doesn't work. I could not find the method in the java code.... ``` UserDaoImplはabstractでなく、UserDao内のabstractメソッドinsertUsersTickets-IoAF18A(UsersTicketsTableRecord)をオーバーライドしません ``` – iioiia Jan 23 '22 at 08:29
  • Can you please show me your UserDao code? I would like to know why the method suffix is IoAF18A. – Toshihiro Nakamura Jan 23 '22 at 15:19
  • I added UserDao.kt at the end of the question ;; – iioiia Jan 24 '22 at 14:51
  • Thank you. You'd need to use `org.seasar.doma.jdbc.Result` instead of `kotlin.Result`. – Toshihiro Nakamura Jan 24 '22 at 15:25
  • I could start the Application !! Thanks :) I'm grateful for your comment !! – iioiia Jan 25 '22 at 00:59