Java 无法转换为类,因为它们位于加载程序“app”的未命名模块中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/54536895/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 01:05:10  来源:igfitidea点击:

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

javaspring-bootjava-9java-module

提问by Francisco Mateo

I'm trying to create a bean from sources that were generated by wsdl2java.

我正在尝试从由wsdl2java.

Every time I try to run my Spring Boot app, I get the following error:

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

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')

引起:java.lang.ClassCastException:class org.apache.cxf.endpoint.ClientImpl 不能被转换为类 com.xignite.services.XigniteCurrenciesSoap(org.apache.cxf.endpoint.ClientImpl 和 com.xignite.services.XigniteCurrenciesSoap 是在加载程序'app'的未命名模块中)

I'm not sure how exactly I'm to include generated sources in my main Spring Boot application as a module.

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

My directory structure is:

我的目录结构是:

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

Relevant system info:

相关系统信息:

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)
  • Spring Boot 2.1.2.RELEASE
  • Gradle 5.2
  • Spring Boot 2.1.2.RELEASE
  • 摇篮 5.2

I've also uploaded the project onto Github here: https://github.com/ciscoo/soap-consumption-spring-boot

我也在这里将项目上传到 Github:https: //github.com/ciscoo/soap-consumption-spring-boot

回答by orirab

I had a similar case, and (as mentioned by @Holger in the comment) the module info in the message is simply misleading - this is an actual case of trying to cast something to something that doesn't match it.

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

In your case, ClientImplsimply is not a subtype of XigniteCurrenciesSoap.

在您的情况下,ClientImpl根本不是XigniteCurrenciesSoap.

回答by Edward Hochwand

The stacktrace is trying to tell you that you have casted XigniteCurrenciesSoapto ClientImpl.

堆栈跟踪试图告诉您您已转换XigniteCurrenciesSoapClientImpl.

Such as the example below:

比如下面的例子:

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

You have to find out where you did that in your code and fix it.

您必须找出您在代码中的位置并修复它。