问题
I have worked on implementation of the Entity remote service. I have created one custom service method in EntityServiceImpl,Created custom service method providing service through InstitutionServiceUtil. After deploy the portlet, while sending request to service method through from browser window,I am getting below Exception
exception":"java.lang.ClassCastException: com.institutions.model.impl.InstitutionImpl
cannot be cast to com.institutions.model.Institution
Note: If I send the request after restart the server, I didn't get above exception.
How to resolve the above Exception?
回答1:
I assuming that InstitutionImpl
implements the interface Institution
. If so, then the root cause of the exception is classloading: Classloader A did load Institution
but InstitutionImpl
was loaded from a different classloader. Two classes in Java are only equivalent if the fully qualified name and the classloader are the same.
I don't know enough about liferay to tell you how it's class loading works. But to solve the problem, you need to find out if the Institution
interface could already be around when you try to load your implementation (maybe from a previous deployment attempt).
回答2:
While deploying the portlets that throws the class cast exception, do the following:
- deploy the application in the liferay/deploy.
- shutdown the liferay
- move the service jar from the WEB-INF/lib from the portlet to the /lib/ext of the tomcat
- remove the temp and work folder from the tomcat
- restart the tomcat.
OR ...what worked for me was
- change the package name while building the service.xml in the service.xml file
Or if you have already built the service, do these steps
Just delete the 5 packages that are created from the service builder, i.e
model.impl
service.base
service.http
service.impl
service.persistence
delete the .xml generated in the META-INF folder except for the file ext-spring.xml
- delete the XX-service.jar from the docroot/lib folder
- delete the service folder in the docroot folder.
- change the package name in the service.xml and build the path.
来源:https://stackoverflow.com/questions/27286613/exceptionjava-lang-classcastexception-in-liferay-service-builder