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

问题描述 投票:0回答:6

我正在尝试从

wsdl2java
生成的源创建一个 bean。

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

引起:java.lang.ClassCastException:类 org.apache.cxf.endpoint.ClientImpl 无法转换为类 com.xignite.services.XigniteCurrencySoap (org.apache.cxf.endpoint.ClientImpl 和 com.xignite.services.XigniteCurrencySoap 位于未命名模块中 加载器“应用程序”)

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

我的目录结构是:

├── build
│   └── generatedsources
│       └── src
│           └── main
│               └── java
│                   └── com
│                       └── xignite
│                           └── services
│      
└── src
    └── main
        ├── java
        │   └── io
        │       └── mateo
        │           └── stackoverflow
        │               └── 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)
  • Spring Boot 2.1.2.RELEASE
  • 摇篮5.2

我还将该项目上传到了 Github:https://github.com/ciscoo/soap-conspiration-spring-boot

java spring-boot java-9 java-module
6个回答
79
投票

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

就您而言,

ClientImpl
根本不是
XigniteCurrenciesSoap
的子类型。


2
投票

堆栈跟踪试图告诉您,您已将

XigniteCurrenciesSoap
转换为
ClientImpl

比如下面的例子:

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

您必须找出代码中的何处执行此操作并修复它。


1
投票

我与上面的异常非常相似。

java.lang.ClassCastException: class [B cannot be cast to class org.apache.avro.generic.GenericRecord ([B is in module java.base of loader 'bootstrap'; org.apache.avro.generic.GenericRecord is in unnamed module of loader org.springframework.boot.loader.LaunchedURLClassLoader 

根本原因是我的 Gradle 依赖项有排除语句,即

exclude group: 'org.springframework.cloud', module: 'spring-cloud-stram-binder-kafka',

我评论如下,之后一切正常:

implementation ('com.xyz.lux:lux-acitor:1.25.0') {
  //exclude group: 'org.springframework.cloud', module: 'spring-cloud-stream-binder-kafka'
  exclude group: 'org.slf4j', module: 'slf4j-reload4j'
  exclude group: 'io.confluent', module: 'confluent-log4j'
}

0
投票

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


0
投票

我在使用 Spring Cloud Stream Kafka 时遇到了同样的问题,当我尝试使用消息时它会抛出异常。

就我而言,这是因为 Spring boot 需要任何类型的依赖关系来允许 Serde(序列化或反序列化)。刚刚添加了 json 。

       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-json</artifactId>
            <version>3.0.2</version>
            <scope>compile</scope>
        </dependency>

在那之后我就能继续前进。请记住,如果您有 Spring Web 依赖项,那么上述依赖项会自动包含在内


0
投票

在我的例子中,我有一个带有以下 lombok 注释的父类

@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
public class Parent {
...
}

然后子班看起来像这样

public class Child extends Parent {}

最后我通过将这两个 lombok 注释添加到子类中使其工作

@SuperBuilder
@EqualsAndHashCode(callSuper = true)
© www.soinside.com 2019 - 2024. All rights reserved.