java.lang.LinkageError: loader constraint violation; when resolving interface method (in service class)

java.lang.LinkageError: loader constraint violation; when resolving interface method (in service class)

我的项目结构就像有三个包,即 Rest(其中放置了 Rest API 及其实现 类)、Service API(其中定义了服务接口) 和 Service Impl(其中放置了 Service API 的实现)。我在 PersonalInfoServiceImpl 中的代码只是将 PersonalInfoRequestBean 值设置为 PersonalInfoResponseBean(+ 一些其他属性)对象并返回 PersonalInfoResponseBean。它工作正常。但是在与更多的拦截器集成之后,现在我突然开始在这段代码中收到以下错误:

Caused by java.lang.LinkageError: loader constraint violation: when resolving 
interface method "personal.info.service.api.PersonalInfoService.getPersonalInfoDetails(Lcom//personal/info/model/PersonalInfoRequestBean;)Lpersonal/info/model/PersonalInfoResponseBean;" 
the class loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) 
of the current class, personal/info/rest/impl/PersonalInfoRESTServiceImpl, 
and the class loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) 
for the method's defining class, personal/info/service/api/PersonalInfoService, 
have different Class objects for the type personal/info/model/PersonalInfoRequestBean 
used in the signature at personal.info.rest.impl.PersonalInfoRESTServiceImpl.getPersonalInfoDetail(PersonalInfoRESTServiceImpl.java:112)

有人可以帮我解决这个问题吗?。我们正在使用 Apache karaf 来部署我们的服务。所以,如果是karaf/delpoyment/maven依赖关系,那么调试这个问题的方法是什么。

此错误消息表示,您有 2 个使用不同 class 加载器加载的 classes personal/info/model/PersonalInfoRequestBean。 其中一个 class 加载器加载接口 PersonalInfoService 和其他加载实现 PersonalInfoRESTServiceImpl。 你应该避免这种情况,你的 class personal/info/model/PersonalInfoRequestBean 应该只由加载接口的 classloader 定义。