针对 hibernate-validator 国家/地区特定限制的编译错误

问题描述 投票:0回答:1

我的项目是一个带有 jax-rs/resteasy 实现的 JEE,我正在使用带有 beans 验证的 Resteasy 验证(hibernate-validator)。当我尝试通过 Maven 构建项目时,错误是:

employee.java:[6,10] 包 org.hibernate.validator.constraints.br 不存在
找不到符号类 CPF

package br.com.example.dto;

import org.hibernate.validator.constraints.br.CPF;

public class Employee {

    @NotBlank(message = "blank")
    @CPF(message = "invalid")
    private String cpf;
}

Pom.xml:

<dependency>
    <groupId>org.wildfly.bom</groupId>
    <artifactId>wildfly-jakartaee8-with-tools</artifactId>
    <version>${wildfly.version}</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

如果我删除@CPF验证,一切正常。

我的问题:为什么在

<artifactId>hibernate-validator</artifactId>
内声明的
wildfly-jakartaee8-with-tools
不适用于该国家/地区的特定约束?

maven hibernate-validator
1个回答
0
投票

导入

BOM
不会执行任何操作(就设置依赖项而言)。您仍然需要声明项目所需的依赖项。

但是

BOM
对于依赖版本控制来说非常好。在 Maven 中,您应该将该 BOM 文件设置为
pom.xml
:

的父文件
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.wildfly.bom</groupId>
        <artifactId>wildfly-jakartaee8-with-tools</artifactId>
        <version>26.1.3.Final</version>
        <type>pom</type>
    </parent>

    <dependencies>
        <!-- required dependencies -->
    </dependencies>

    <!-- ... -->

</project>

之后,您不需要指定父 pom 文件的

<dependencyManagement>
部分中声明的依赖项的任何版本。例如:

<dependency>
    <groupId>org.hibernate.validator</groupId>
    <artifactId>hibernate-validator</artifactId>
</dependency>

我也看了

wildfly-jakartaee8-with-tools
,没有找到
hibernate-validator
。你应该检查一下。

© www.soinside.com 2019 - 2024. All rights reserved.