无法转换为 class,因为它们位于加载程序 'app' 的未命名模块中

Cannot be cast to class because they are in unnamed module of loader 'app'

我正在尝试从 wsdl2java 生成的源创建一个 bean。

每次我尝试 运行 我的 Spring 引导应用程序时,我都会收到以下错误:

Caused by: java.lang.ClassCastException: class org.apache.cxf.endpoint.ClientImpl cannot be cast to class com.xignite.services.XigniteCurrenciesSoap (org.apache.cxf.endpoint.ClientImpl and com.xignite.services.XigniteCurrenciesSoap are in unnamed module of loader 'app')

我不确定如何将生成的源作为模块包含在我的主 Spring 引导应用程序中。

我的目录结构是:

├── build
│   └── generatedsources
│       └── src
│           └── main
│               └── java
│                   └── com
│                       └── xignite
│                           └── services
│      
└── src
    └── main
        ├── java
        │   └── io
        │       └── mateo
        │           └── Whosebug
        │               └── soapconsumption
        └── resources
           └── wsdls

相关系统信息:

openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)

我也已将项目上传到 Github 此处:https://github.com/ciscoo/soap-consumption-spring-boot

我有一个类似的案例,并且(正如@Holger 在评论中提到的)消息中的模块信息只是误导 - 这是一个尝试将某些内容转换为与其不匹配的内容的实际案例.

在你的例子中,ClientImpl 根本不是 XigniteCurrenciesSoap 的子类型。

堆栈跟踪试图告诉您您已将 XigniteCurrenciesSoap 转换为 ClientImpl

例如下面的例子:

Object returnObj= getXigniteCurrenciesSoap();
return (ClientImpl) returnObj;

你必须找出你在代码中的哪里做了那个并修复它。

我遇到了同样的问题。我的问题是我已经在另一个地方有一个同名的class。所以尝试更改 class 名称。