[apache/dubbo]spring-boot 下使用默认序列化会出现Hessian/Burlap:class is an unknown class in WebappClassLoader

2024-04-11 729 views
4

这个错误在服务消费者会出现

2017-11-06 10:06:09 CST api-mall-manage WARN  com.alibaba.com.caucho.hessian.io.SerializerFactory 528 getDeserializer - Hessian/Burlap: 'com.mit.service.define.v1.entity.TokenPkg' is an unknown class in WebappClassLoader
  context: /
  delegate: false
----------> Parent Classloader:
sun.misc.Launcher$AppClassLoader@42a57993:
java.lang.ClassNotFoundException: com.mit.service.define.v1.entity.TokenPkg

但是不影响服务正常调用

猜测,我的程序是使用了spring-boot的,WebappClassLoader会首先去META-INF下面去找lib文件,找不到,就报我刚才那个错误,但是spring-boot打的包是在BOOT-INF下面的,会不会是这个原因,由于服务提供者是非web的,所以不会出现这个问题?

回答

5

可能用了devtools库了,去掉应该就ok了

2

@wu191287278 没有引用devtools

<!-- spring boot starter -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>logback-classic</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>

<!-- dubbo -->
<dependency>
    <groupId>io.dubbo.springboot</groupId>
    <artifactId>spring-boot-starter-dubbo</artifactId>
    <version>${spring-boot-starter-dubbo.version}</version>
    <exclusions>
        <exclusion>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
        </exclusion>
        <exclusion>
            <groupId>com.101tec</groupId>
            <artifactId>zkclient</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>dubbo</artifactId>
    <version>${dubbo.version}</version>
    <exclusions>
        <exclusion>
            <artifactId>log4j</artifactId>
            <groupId>log4j</groupId>
        </exclusion>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
    </exclusions>
</dependency>

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

<!-- kyro -->
<dependency>
    <groupId>com.esotericsoftware.kryo</groupId>
    <artifactId>kryo</artifactId>
    <version>${kryo.version}</version>
</dependency>
<dependency>
    <groupId>de.javakaffee</groupId>
    <artifactId>kryo-serializers</artifactId>
    <version>${kryo-serializers.version}</version>
</dependency>

<!-- zookeeper -->
<dependency>
    <groupId>org.apache.zookeeper</groupId>
    <artifactId>zookeeper</artifactId>
    <version>${apache-zookeeper.version}</version>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
        <exclusion>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>zkclient</artifactId>
    <version>${alibaba-zkclient.version}</version>
</dependency>

<!--rest -->
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxrs</artifactId>
    <version>${resteasy.version}</version>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-validator-provider-11</artifactId>
    <version>${resteasy.version}</version>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-client</artifactId>
    <version>${resteasy.version}</version>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-netty</artifactId>
    <version>${resteasy.version}</version>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-multipart-provider</artifactId>
    <version>${resteasy.version}</version>
</dependency>
<!--json -->
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jackson2-provider</artifactId>
    <version>${resteasy.version}</version>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxb-provider</artifactId>
    <version>${resteasy.version}</version>
</dependency>

<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>${javax-validation-api.version}</version>
</dependency>

<!--tomcat -->
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-core</artifactId>
    <version>${apache-tomcat-embed.version}</version>
</dependency>

<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-logging-juli</artifactId>
    <version>${apache-tomcat-embed.version}</version>
</dependency>

<!-- dom4j -->
<dependency>
    <groupId>org.dom4j</groupId>
    <artifactId>dom4j</artifactId>
    <version>${dom4j.version}</version>
</dependency>

<!-- http client -->
<dependency>
    <groupId>commons-httpclient</groupId>
    <artifactId>commons-httpclient</artifactId>
    <version>${commons-httpclient.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>${apache-commons-lang3.version}</version>
</dependency>
<dependency>
    <groupId>commons-codec</groupId>
    <artifactId>commons-codec</artifactId>
    <version>${commons-codec.version}</version>
</dependency>

<dependency>
    <groupId>javax.el</groupId>
    <artifactId>javax.el-api</artifactId>
    <version>${javax-el.version}</version>
</dependency>

<dependency>
    <groupId>org.glassfish.web</groupId>
    <artifactId>javax.el</artifactId>
    <version>${javax-el.version}</version>
</dependency>

<!-- javassist -->
<dependency>
    <groupId>javassist</groupId>
    <artifactId>javassist</artifactId>
    <version>${javassist.version}</version>
</dependency>
2

检查com.mit.service.define.*所在的jar包,服务端与消费端版本是否一致。

0

@wuwen5 这个define是单独jar,服务者和消费者都引用的这个包,是一样的,1.0.0-SNAPSHOT</define.version>,主要是不影响服务调用,只是消费者不断的出现这些警告

1

参考@wuwen5的建议,hessian本身是兼容两端实体定义不匹配的,以上warn日志很像是此种场景导致的。 根据接口所用的DTO实体类:

  1. 检查运行期消费端和服务端所使用的依赖版本是否一致
  2. 检查你提到的classloader、部署环境等
6

原则上跨系统之间的依赖不应该使用SNAPSHOT版本,SNAPSHOT版本并不能保证jar包一致。可以对比下服务端和消费端这个jar包。

推荐 https://github.com/oldratlee/useful-scripts#coffee-java相关脚本 这里的脚本检查。

2.show-duplicate-java-classes 找出jar文件和class目录中的重复类。用于排查Java类冲突问题。

4

经过各位大佬指导,我也经过排查,并没有解决这个问题.不知道有没有大神愿意帮助解决一下。 已经排查过没有重复的lib包,版本也是一致,这是通过maven工具检查,以及通过jd-gui检查jar包确认的

1

这种情况可能有两种原因。

  • 第一种是生产者和消费者两端引用的client.jar不一致,导致dubbo在通过hessian序列化和反序列化时检查类信息报WARN;

  • 还有一种是生产者返回结果中存在属性的引用类型不在client.jar,例如生产者返回Result,内部有属性是Object param,生产者将service内部的dto赋值给param。然后消费者端dubbo在反序列化Result时发现找不到这个dto,也可能会报class not found;

不过这只是警告,不影响功能,楼主可以按照上面两种方式考虑下。