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
Build class
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
}
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