问题
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
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: 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?
(note that all projects do have an empty META-INF/beans.xml in their resources dir)
回答1:
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.
I suppose you only have the issue with quarkusDev? Not when you execute the -runner.jar
?
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.
来源:https://stackoverflow.com/questions/59523154/classcastexception-in-multi-module-project-running-on-quarkus-gradle