简体   繁体   English

无法在 IntelliJ IDEA 中导入 javax.validation.constraints

[英]Cannot import javax.validation.constraints in IntelliJ IDEA

I can't import that simple library, i have all jar files, also i tried Ivalidate Caches / Restart.我无法导入那个简单的库,我有所有的 jar 文件,我也试过 Ivalidate Caches / Restart。 Maybe i have to add validation to build path, but i don't know to which file.也许我必须添加验证来构建路径,但我不知道哪个文件。 在此处输入图像描述

Got it.知道了。

  1. File -> Project Structure文件 -> 项目结构
  2. In Modules click Dependecies, then click green "+" on the right sideModules中单击 Dependecies,然后单击右侧的绿色“+”
  3. Click JARs or directiories... and add JAR files单击JARs 或 directories...并添加 JAR 文件
  4. Click OK点击确定

    THEN:然后:

  5. File -> Project Structure文件 -> 项目结构
  6. In Artifacts click FIX button on right bottom sizeArtifacts中单击右下角的FIX按钮
  7. Click OK点击确定

You just need to add the dependency Validation API in the pom.xml :您只需要在pom.xml中添加依赖验证 API

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

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

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.你显然忘了声明你的依赖关系,这就是为什么 IDEA 不知道在哪里寻找你试图导入的类。

You just need to add spring-boot-starter-validation dependency in build.gradle file你只需要在build.gradle文件中添加spring-boot-starter-validation依赖

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

Try this,试试这个,

Step-by-step:一步步:

  1. Open "build.gradle" file.打开“build.gradle”文件。 It's in your root folder project;它在您的根文件夹项目中;

  2. Include the line below inside "dependencies{ }": implementation group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'在“dependencies{}”中包含以下行:实施组:'javax.validation',名称:'validation-api',版本:'2.0.1.Final'

  3. Save and close build.gradle file;保存并关闭 build.gradle 文件;

  4. Next, you will see a short notification on the top of your screen to "Load Gradle Changes".接下来,您将在屏幕顶部看到一条简短的通知“加载 Gradle 更改”。 Click on it.点击它。

If you don't see any notification, click on Gradle side bar, and then click on "Reload All Gradle Projects".如果您没有看到任何通知,请单击 Gradle 侧边栏,然后单击“重新加载所有 Gradle 项目”。

  1. That's all, Your annotation @Valid, @NotBlank ou @NotNull.仅此而已,您的注释 @Valid、@NotBlank 或 @NotNull。 will work.将工作。

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.如果您在尝试导入 Maven 项目后遇到此错误,可能是您需要在导入项目向导中选中“自动导入 Maven 项目”。 Without that the IntelliJ build may not be able to locate Maven dependencies, even if they are declared in pom.xml files.否则 IntelliJ 构建可能无法找到 Maven 依赖项,即使它们是在 pom.xml 文件中声明的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 javax.validation.constraints中的转义序列无效 - Invalid escape sequencein javax.validation.constraints 原始布尔值的 javax.validation.constraints? - javax.validation.constraints for primitive boolean? 来自 javax.validation.constraints 的注释不起作用 - Annotations from javax.validation.constraints not working 关注点重复javax.validation.constraints和javax.persistence.Column - Duplication of concerns javax.validation.constraints and javax.persistence.Column 以编程方式“关闭”bean验证(javax.validation.constraints) - “Turn off” bean validation programmatically (javax.validation.constraints) 结合自定义 ConstraintValidator 的 javax.validation.constraints 注释 - Annotations from javax.validation.constraints in combination with custom ConstraintValidator 来自javax.validation.constraints的注释不起作用(忽略) - Annotations from javax.validation.constraints not working (ignored) Java 中的 json 验证器 - 使用 javax.validation.constraints - json validator in Java - using javax.validation.constraints 如何为 `javax.validation.constraints` 注释添加自定义验证器? - how add custom validator for `javax.validation.constraints` annotation? Swagger软件包javax.validation.constraints不存在 - Swagger package javax.validation.constraints does not exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM