@tabe187 (Toru Abe)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

Bean Validationの設定について

Bean Validationを利用してユーザー登録のバリデーション処理を行いたい

Bean Validationを利用してユーザー登録のバリデーション処理を行いたいが下記エラーが発生しています。

	The import javax.validation cannot be resolved
	The import javax.validation cannot be resolved
	Size cannot be resolved to a type
	Size cannot be resolved to a type
	Email cannot be resolved to a type

自分で試したこと

調べてみると"build gradle"に以下を追加する必要があるという記事を見かけたので試してみたのですが、
解決しません。

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-validation'
}

いかにvalidationを記載していおります。

package com.example.demo.form;

import lombok.Data;
// import追加
import javax.validation.constraints.Email;
import javax.validation.constraints.Size;

@Data
public class UserForm {

    // nameへのバリデーション設定を追加
    @Size(min = 1, max = 200)
    private String name;

    // emailへのバリデーション設定を追加
    @Size(min = 1, max = 200)
    @Email
    private String email;
}
0 likes

1Answer

spring-boot-starter-validationがうまく読み込めてないようですね。

調べてみると"build gradle"に

build.gradleの間違いでしょうか。このファイルの全体を質問文に貼るとよいです。

Bean Validationを利用してユーザー登録のバリデーション処理を行いたいが下記エラーが発生しています。

直前に行った動作(コマンド)を書いてください。

また使っている開発環境(eclipse, intelliJなど)も書くととよいです。

1Like

Comments

  1. @tabe187

    Questioner

    コメントありがとうございます。
    コメントをヒントにbuild.gradleをrefreshしたところ読み込まれました。
    また教えていただいたことは次回以降の質問に行かさせていただきます。
    この度はありがとうございました。

Your answer might help someone💌