在 Quarkus (gradle) 上运行的多模块项目中的 ClassCastException [英] ClassCastException in multi-module project running on Quarkus (gradle)

查看:79
本文介绍了在 Quarkus (gradle) 上运行的多模块项目中的 ClassCastException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎在多模块项目中遇到了奇怪的 classcast 异常.以下是项目结构的简要概述:

I seem the get weird classcast exceptions in multi-module project. Here is an shortened overview of the project structure:

Project: dto-commons
    contains
        -> AuditingEntityObjectSelector (a normal java class)
        -> AbstractAuditingEntity (JPA @MappedSuperClass)

Project: model
    contains lots of JPA entities, which all extend AbstractAuditingEntity from the project 'dto-commons'
    depends on 
        -> dto-commons

Project: selectors
    contains
        -> SampleRequestSelector (a normal java class which extends AuditingEntityObjectSelector from the project 'dto-commons'
    depends on 
        -> model


Project:mainservices
    - model
    - selectors
    - dto-commons

Project:rest-api   --> This project is launched with quarkusDev (gradle)
    - mainservices

我创建了一个小测试资源,在其中注入了一些服务、EntityManager 等.一切似乎都在工作,除了我得到非常奇怪的 ClassCastExceptions

I've created a little testresource where I inject some services, an EntityManager etc. Everything seems to be working, except that I get very weird ClassCastExceptions

java.lang.ClassCastException: 类com.geodesk.queryinfrastructure.selector.SampleRequestSelector 不能上课com.geodesk.domain.queryinfrastructure.AuditingEntityObjectSelector

java.lang.ClassCastException: class com.geodesk.queryinfrastructure.selector.SampleRequestSelector cannot be cast to class com.geodesk.domain.queryinfrastructure.AuditingEntityObjectSelector

一些调试显示了以下内容:

Some debugging shows me the following:

new SampleRequest() instanceof AbstractAuditingEntity --> true (which is correct)
new SampleRequestSelector() instanceof AuditingEntityObjectSelector --> false (which is NOT correct)

这可能是一个类加载问题,但我不知道是什么导致了这个问题.

This is probably a classloading issue, but I can't figure out what is causing this.

SampleRequest.class.classLoader == AbstractAuditingEntity.class.classloader --> true 
SampleRequestSelector.class.classLoader == AuditingEntityObjectSelector.class.classloader --> false (don't know for sure, but I think that should be true)

谁能给我指出正确的方向?

Anyone can point me in the right direction?

(请注意,所有项目的资源目录中都有一个空的 META-INF/beans.xml)

(note that all projects do have an empty META-INF/beans.xml in their resources dir)

推荐答案

这看起来像是我们的类加载器问题的另一部分.我们目前正在积极致力于修复它们,但这不是一个容易的主题.

This looks like another installment of our class loader issues. We are currently actively working on fixing them but it's not an easy subject.

我想你只有 quarkusDev 的问题?不是当你执行 -runner.jar 时?

I suppose you only have the issue with quarkusDev? Not when you execute the -runner.jar?

如果您可以尝试将一个简单的复制器放在一起并打开一个 GH 问题,这样我们就可以确保当前的类加载器工作也解决了这个问题,那将会很有帮助.

It would be helpful if you could try to put together a simple reproducer and open a GH issue so that we can be sure the current class loader work fixes this issue too.

这篇关于在 Quarkus (gradle) 上运行的多模块项目中的 ClassCastException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆