Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode, Gradle, Spring Boot, Can't import javax.validation

All.
I want to use @Valid and @NotEmpty in the spring boot(2.3.0) framework.
But I was unable to import javax.validation so I couldn't.
Here is the screen and build.gradle file I am currently experiencing:

  1. Can't be used @Valid annotationenter image description here
  2. Can't be used @NotEmpty annotationenter image description here

<File: build.gradle>

plugins {
    id 'org.springframework.boot' version '2.3.0.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'java'
}

group = 'kr.co.fastcampus'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

configurations {
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    //  Spring Boot
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-validation'

    //  Database
    implementation 'com.h2database:h2'

    compileOnly 'org.projectlombok:lombok'

    developmentOnly 'org.springframework.boot:spring-boot-devtools'

    annotationProcessor 'org.projectlombok:lombok'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

test {
    useJUnitPlatform()
}
like image 571
Changjoo Sohn Avatar asked Mar 02 '23 06:03

Changjoo Sohn


1 Answers

I came here with the same issue, but my problem was that I forgot to add this line to build.gradle.

implementation('org.springframework.boot:spring-boot-starter-validation')

I know this was not your issue, but just posting this here for others who face the same issue like me and stumble on to this question.

like image 153
VishnuVS Avatar answered Mar 12 '23 02:03

VishnuVS