首页 > 解决方案 > Quarkus + 子类 + ClassCastException

问题描述

我正在使用 Quarkus 的 vert.x 扩展,我想继承 WebClient

@Inject
Vertx vertx;

private CustomWebClient usersApiClient;

@PostConstruct
void initialize() {
    this.usersApiClient = (CustomWebClient) WebClient.create(vertx, new WebClientOptions()....)
}

现在 CustomWebClient 是空的,只是扩展了 Web 客户端

public class CustomWebClient extends io.vertx.mutiny.ext.web.client.WebClient {

但是我在运行时得到一个 ClassCastException (例如在 quarkus:dev 中)

Caused by: java.lang.ClassCastException: class io.vertx.mutiny.ext.web.client.WebClient
cannot be cast to class xxx.CustomWebClient (io.vertx.mutiny.ext.web.client.WebClient is in
unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @760f1081; 
xxx.CustomWebClient is in unnamed module of loader.
io.quarkus.bootstrap.classloading.QuarkusClassLoader @55be9b4e)

我需要在类加载器中注册这个类吗?

标签: javavert.xquarkus

解决方案


推荐阅读