美文网首页
springboot dubbo3 集成validation 的

springboot dubbo3 集成validation 的

作者: 草祭木初 | 来源:发表于2025-01-20 14:31 被阅读0次

版本
spring boot: 3.4.1
dubbo:3.3.1
java17

不能使用

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

否则会在provider端造成一个死循环(几秒钟就会出几百兆的日志)
异常信息是

org.apache.dubbo.remoting.http12.exception.EncodeException: Internal Server Error
。。。
Caused by: org.apache.dubbo.common.serialize.SerializationException: java.lang.IllegalArgumentException: [Serialization Security] Serialized class org.apache.dubbo.remoting.http12.exception.EncodeException is not in allow list. Current mode is `STRICT`, will disallow to deserialize it by default. Please add it into security/serialize.allowlist or follow FAQ to configure it.
    ... 1024 common frames omitted
Caused by: java.lang.IllegalArgumentException: [Serialization Security] Serialized class org.apache.dubbo.remoting.http12.exception.EncodeException is not in allow list. Current mode is `STRICT`, will disallow to deserialize it by default. Please add it into security/serialize.allowlist or follow FAQ to configure it.

我跟踪的一下代码,但没有找到具体原因

之后看了一下dubbo官方的例子代码:
https://gitcode.com/gh_mirrors/du/dubbo-samples/blob/master/2-advanced/dubbo-samples-validation/pom.xml
用的是这个

        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>2.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.el</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>6.1.5.Final</version>
        </dependency>

但javax.validation已经被弃用了

所以直接使用

       <dependency>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>8.0.2.Final</version>
       </dependency>

一切恢复平静

具体原因找到了
是因为dubbo 在3.1.6 开始,开启另一个序列化检查模式,这个检查模式认定EncodeException 为非法的序列化类,所以报错
但为什么会死循环还没没有搞清楚。明明EncodeException 是dubbo自带的异常,也不是我定义的,不知道为什么就非法了。

具体请参照官方文档(有解决方案):https://cn.dubbo.apache.org/zh-cn/overview/mannual/java-sdk/tasks/security/class-check/
https://cn.dubbo.apache.org/zh-cn/overview/mannual/java-sdk/reference-manual/serialization/serialization/

我采用的是比较极端的解决方案:关掉这个检查

dubbo.application.serialize-check-status=DISABLE

相关文章

网友评论

      本文标题:springboot dubbo3 集成validation 的

      本文链接:https://www.haomeiwen.com/subject/acbxujtx.html