Pre-check

  • [x] I am sure that all the content I provide is in English.

Search before asking

  • [x] I had searched in the issues and found no similar issues.

Apache Dubbo Component

  • Java 17
  • spring boot 3.4.4

Dubbo Version

dubbo 3.2.18

Steps to reproduce this issue

请问在springboot 项目中,如何全局配置 jvalidationNew ?

使用 @DubboService(validation = "jvalidationNew") 有效,

// 生效
@DubboService(validation = "jvalidationNew")
public class OpenPaymentImpl implements OpenPayment {
}

但若只配置 dubbo.consumer.validation=jvalidationNew , @DubboService() 不设置validation 则不生效。

// application.properties
dubbo.consumer.validation=jvalidationNew  


// 执行校验,但调用里面的方法会报错(和1楼的错误一样)
@DubboService(validation = "true")
public class OpenPaymentImpl implements OpenPayment {
}
// 无法执行校验,但调用里面的方法不会报错
@DubboService
public class OpenPaymentImpl implements OpenPayment {
}

为啥不用英语提问?

中国人为啥要用英语 ? 为啥不然老外学中文?

Comment From: wcy666103

Please re-submit this pr in English only.

Comment From: heliang666s

首先,这个是因为@DubboService(validation = "true")的问题,你配置为 true 的话 Dubbo 默认走的是 jvalidation 而不是 jvalidationNew,正确的配置应该是 @DubboService(validation = "jvalidationNew")。其次,如果你不想一个一个注解地加,全局配置应该是 provider 而不是comsumer @zuihou

Comment From: kaiser20106

下面是我个人根据代码和文档汇总结果

dubbo:
  # 参数校验
  consumer:
    validation: true
  provider:
    validation: true
//实体类
public class GoodEntity {

    @Null(groups = GoodService.InsertSelective.class, message = "新增时id必须为空")
    private Integer id;
}

//服务
public interface GoodService {


    @interface InsertSelective {} //与方法同名接口,首字母大写,用于区分验证场景,如:@NotNull(groups = GoodService.InsertSelective.class),可选
    ResponseEntity<Integer> insertSelective(@RequestBody GoodEntity goodEntity);


}

"message": "Failed to validate service: org.example.cloud.dubbo.GoodService , method: insertSelective, cause: [ConstraintViolationImpl{interpolatedMessage='新增时id必须为空', propertyPath=id, rootBeanClass=class org.example.cloud.entity.GoodEntity , messageTemplate='新增时id必须为空'}]",

注意是与方法同名接口 而不是插入方法用 @interface Save {}

参考用例