jakarta-eejax-rskaraflinkageerror

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


My project structure is like there are three bundles namely Rest (in which Rest API and its Implementaion classes are placed), Service API (in which service Interfaces are defined) and Service Impl (in which implementaion of Service API is placed). My code in PersonalInfoServiceImpl just setting the PersonalInfoRequestBean values to PersonalInfoResponseBean (+ few more properties) object and returning PersonalInfoResponseBean. It was working fine. But after integration with few more Interceptors, now suddenly I started getting the following error in this code:

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)

Can someone help me in this issue?. We are using Apache karaf for deploying our services. So, if it is related with karaf/delpoyment/maven dependencies, then what is the way to debug this issue.


Solution

  • This error message means, that you have 2 loaded classes personal/info/model/PersonalInfoRequestBean with different classloaders. One of theese classloaders loads interface PersonalInfoService and other loads implementation PersonalInfoRESTServiceImpl. You should avoid this and your class personal/info/model/PersonalInfoRequestBean should be only defined by classloader, that loads interface.