exception“:”java.lang.ClassCastException in liferay service builder

旧时模样 提交于 2019-12-10 10:56:24

问题


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:

  1. deploy the application in the liferay/deploy.
  2. shutdown the liferay
  3. move the service jar from the WEB-INF/lib from the portlet to the /lib/ext of the tomcat
  4. remove the temp and work folder from the tomcat
  5. restart the tomcat.

OR ...what worked for me was

  1. 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

  1. Just delete the 5 packages that are created from the service builder, i.e

    model.impl

    service.base

    service.http

    service.impl

    service.persistence

  2. delete the .xml generated in the META-INF folder except for the file ext-spring.xml

  3. delete the XX-service.jar from the docroot/lib folder
  4. delete the service folder in the docroot folder.
  5. change the package name in the service.xml and build the path.


来源:https://stackoverflow.com/questions/27286613/exceptionjava-lang-classcastexception-in-liferay-service-builder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!