验证扩展

扩展说明

参数验证扩展点。

扩展接口

com.alibaba.dubbo.validation.Validation

扩展配置

  1. <dubbo:service validation="xxx,yyy" />
  2. <!-- 缺省值设置,当<dubbo:service>没有配置validation属性时,使用此配置 -->
  3. <dubbo:provider validation="xxx,yyy" />

已知扩展

com.alibaba.dubbo.validation.support.jvalidation.JValidation

扩展示例

Maven 项目结构:

  1. src
  2. |-main
  3. |-java
  4. |-com
  5. |-xxx
  6. |-XxxValidation.java (实现Validation接口)
  7. |-resources
  8. |-META-INF
  9. |-dubbo
  10. |-com.alibaba.dubbo.validation.Validation (纯文本文件,内容为:xxx=com.xxx.XxxValidation)

XxxValidation.java:

  1. package com.xxx;
  2. import com.alibaba.dubbo.validation.Validation;
  3. public class XxxValidation implements Validation {
  4. public Object getValidator(URL url) {
  5. // ...
  6. }
  7. }

XxxValidator.java:

  1. package com.xxx;
  2. import com.alibaba.dubbo.validation.Validator;
  3. public class XxxValidator implements Validator {
  4. public XxxValidator(URL url) {
  5. // ...
  6. }
  7. public void validate(Invocation invocation) throws Exception {
  8. // ...
  9. }
  10. }

META-INF/dubbo/com.alibaba.dubbo.validation.Validation:

  1. xxx=com.xxx.XxxValidation

原文: http://dubbo.apache.org/#!/docs/dev/impls/validation.md?lang=zh-cn