Cannot import javax.validation.constraints in IntelliJ IDEA

岁酱吖の 提交于 2020-12-06 05:51:15

问题


I can't import that simple library, i have all jar files, also i tried Ivalidate Caches / Restart. Maybe i have to add validation to build path, but i don't know to which file.


回答1:


Got it.

  1. File -> Project Structure
  2. In Modules click Dependecies, then click green "+" on the right side
  3. Click JARs or directiories... and add JAR files
  4. Click OK

    THEN:

  5. File -> Project Structure
  6. In Artifacts click FIX button on right bottom size
  7. Click OK



回答2:


What build tool do you use? You obviously forgot to declare your dependencies, that's why IDEA doesn't know where to look for the classes you are trying to import.




回答3:


You just need to add the dependency Validation API in the pom.xml:

<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>2.0.0.Final</version>
</dependency>

Links: https://www.baeldung.com/javax-validation




回答4:


You just need to add spring-boot-starter-validation dependency in build.gradle file

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



回答5:


If you get this error after attempting to import a Maven project, it may be that you need to check "Import Maven projects automatically" in the Import Project wizard. Without that the IntelliJ build may not be able to locate Maven dependencies, even if they are declared in pom.xml files.



来源:https://stackoverflow.com/questions/45035685/cannot-import-javax-validation-constraints-in-intellij-idea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!