无法解析 javax.validation.constraints.Email; 包

huangapple go评论70阅读模式
英文:

Not able to resolve javax.validation.constraints.Email; package

问题

以下是您要翻译的内容:

Belo is my whole Entity class code.

[![enter image description here](https://i.stack.imgur.com/to9M0.png)](https://i.stack.imgur.com/to9M0.png)

package com.email.esp.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

@Entity
@Table(name = "users", uniqueConstraints = { @UniqueConstraint(columnNames = { "email" }) })
public class User {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long userId;

    @Column(nullable = false, length = 30)
    private String name;

    @Email(message = "Email is not valid", regexp = "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=/?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])")
    @NotEmpty(message = "Email cannot be empty")
    private String email;

    @Transient // meaning it will not be saved in DB
    //@Size(min = 5, max = 15, message = "{register.password.size}")
    private String plainPassword; // unencrytped

    @Transient
    private String repeatPassword;

    @Column(nullable = true)
    private String phone;

    @Column(nullable = false, length = 500)
    private String about;

    @Column(nullable = true)
    private String profilePic;
    
    @Column(name="enabled")
    private Boolean enabled = true;

}

我明白您只需要翻译代码部分,不包括问题或其他内容。如果您有其他需要翻译的部分,请告诉我。

英文:

Belo is my whole Entity class code.

无法解析 javax.validation.constraints.Email; 包

package com.email.esp.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
@Entity
@Table(name = "users", uniqueConstraints = { @UniqueConstraint(columnNames = { "email" }) })
public class User {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long userId;
@Column(nullable = false, length = 30)
private String name;
@Email(message = "Email is not valid", regexp = "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])")
@NotEmpty(message = "Email cannot be empty")
private String email;
@Transient // meaning it will not be saved in DB
//@Size(min = 5, max = 15, message = "{register.password.size}")
private String plainPassword; // unencrytped
@Transient
private String repeatPassword;
@Column(nullable = true)
private String phone;
@Column(nullable = false, length = 500)
private String about;
@Column(nullable = true)
private String profilePic;
@Column(name="enabled")
private Boolean enabled = true;
}

I'm trying to use the spring Email core package in my spring boot project. I have added the dependency in my pom file but for some weird reason the import statement for import javax.validation.constraints.Email; is not getting resolved. Any idea why is this happening?? Here is the dependency , i have ...

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.9-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.email</groupId>
<artifactId>esp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>esp</name>
<description>Email Service Provider Using Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

答案1

得分: 1

javax.validation.constraints.Email注解依赖于Jakarta Bean Validation提供的验证。

您可以尝试将spring-boot-starter-validation依赖项添加到您的pom.xml中。 此依赖项包含所有所需的依赖项(包括Jakarta和Hibernate-Validator,这是此验证的兼容验证器)

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
英文:

javax.validation.constraints.Email annotation depends on Jakarta Bean Validation providers for validation.

You could try to add spring-boot-starter-validation dependency to your pom.xml. This dependency contains all the required dependencies (including jakarta and hibernate-validator which is a compliant validator for this)

&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-validation&lt;/artifactId&gt;
&lt;/dependency&gt;

huangapple
  • 本文由 发表于 2023年2月19日 21:27:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/75500453.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定