0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

SpringBoot(Kotlin)でバリデーションがimportできずにエラーになる

Posted at

はじめに

書籍通りにやっていたのにうまくいかない箇所があったのでまとめます
多くの人がつまづきそうですが、わかりやすい記事が見つからなかったのでもしかしたらSpringBootのテンプレート作成の設定が足りていなかったのかもしれないです

問題

以下の書籍のコードでエラーが発生しました

TaskCreateForm.kt
package com.example.todolist

import org.hibernate.validator.constraints.NotBlank
import javax.validation.constraints.Size

class TaskCreateForm {

    @NotBlank
    @Size(max = 20)
    var content: String? = null
}

すると以下のエラーが発生しました

kotlin  | Starting a Gradle Daemon, 23 busy and 3 stopped Daemons could not be reused, use --status for details
kotlin  | > Task :processResources UP-TO-DATE
kotlin  | 
kotlin  | > Task :compileKotlin FAILED
kotlin  | e: /app/src/main/kotlin/com/example/todolist/TaskCreateForm.kt: (3, 12): Unresolved reference: hibernate
kotlin  | e: /app/src/main/kotlin/com/example/todolist/TaskCreateForm.kt: (4, 14): Unresolved reference: validation
kotlin  | e: /app/src/main/kotlin/com/example/todolist/TaskCreateForm.kt: (8, 6): Unresolved reference: NotBlank
kotlin  | e: /app/src/main/kotlin/com/example/todolist/TaskCreateForm.kt: (9, 6): Unresolved reference: Size

しっかりライブラリがインポートできていないようです

解決方法

build.gradle.ktsに以下を追加したら動きました

build.gradle.kts
dependencies {
	implementation("javax.validation:validation-api:2.0.1.Final")
	implementation("org.springframework.boot:spring-boot-starter-validation")

何かを依存に追加すればいいか見つけるのに苦労しました
validation-apiはバージョンをいれないとエラーになってしまうのでそこに時間を使いました

おわりに

インポート周りは調べてもすぐに見つけたい記事がみつからず、調べ方もよくわかっていないので難しいです
はやくインポートに慣れたいです

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?