Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
Daniel Nordhoff-Vergien
Access service from other portlet
3. Mai 2013 07:06

Daniel Nordhoff-Vergien

Rang: New Member

Nachrichten: 7

Eintrittsdatum: 17. März 2013

Neue Beiträge


when I try to access a service created with service builder from another plugin I get the following exception:
 2 ERROR [http-bio-8080-exec-4][render_portlet_jsp:154] java.lang.ClassCastException: myservice.model.Bean cannot be cast to myservice.model.Bean
 3        at myservice.service.base.TaxonLocalServiceClpInvoker.invokeMethod(
 4        at myservice.service.base.TaxonLocalServiceBaseImpl.invokeMethod(
 5        at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(
 6        at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(
 7        at com.liferay.portal.dao.jdbc.aop.DynamicDataSourceTransactionInterceptor.invoke(
 8        at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(
 9        at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(
10        at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(
11        at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(
12        ...

This only happens when the parameter of return value of the service is a "custom" class, not one like java.lang.String. My classes are in a separate jar which is packed as a dependency via maven to both projects.


David H Nebinger
RE: Access service from other portlet
3. Mai 2013 10:37

David H Nebinger

Community Moderator

Rang: Liferay Legend

Nachrichten: 13216

Eintrittsdatum: 1. September 2006

Neue Beiträge

You cannot do this.

Service builder crosses the class loader boundary between the plugin providing the service and the plugin consuming the service.

Even though your class is in a separate jar and may be part of both projects, the separate class loaders involve will load classes that cannot be passed across the boundary.

Your two choices would be

a) move the jar file to the global lib (tomcat's lib/ext directory), this would make the instance at the global level so it removes the class loader issue, but the jar cannot be updated when the application container is running.

b) define your objects as entities in the service.xml file. SB can pass entities, but not regular classes. Entities are normally backed by the database, but I have an example here that uses what I call 'fake' entities, or entities that are not backed by the database but are still defined as entities in the service.xml file.

Taking route b) is the best option, as this does not have the requirement of stopping the app container to deploy an update, but it takes more work on your part to get you there.

Participate in the State of Liferay Community 2017. Help the community and even win some prizes!