2

我一直致力于实体远程服务的实现。我在EntityServiceImpl中创建了一个自定义服务方法,创建了通过InstitutionServiceUtil提供服务的自定义服务方法。部署 portlet 后,通过从浏览器窗口向服务方法发送请求时,我遇到了异常

exception":"java.lang.ClassCastException: com.institutions.model.impl.InstitutionImpl 
           cannot be cast to com.institutions.model.Institution

注意:如果我在重新启动服务器后发送请求,我没有得到上述异常。

如何解决上述异常?

4

2 回答 2

4

我假设InstitutionImpl实现了接口Institution。如果是这样,那么异常的根本原因是类加载:类加载器 A 确实加载了Institution,但是InstitutionImpl是从不同的类加载器加载的。只有完全限定名称和类加载器相同时,Java 中的两个类才等效。

我对 liferay 的了解还不够,无法告诉你它是如何加载类的。但是要解决这个问题,您需要确定Institution当您尝试加载您的实现时该接口是否已经存在(可能来自之前的部署尝试)。

于 2014-12-04T08:29:03.893 回答
1

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.
于 2017-02-08T09:44:37.137 回答