Accessing a Service Builder module from a Spring MVC portlet in Liferay DXP
Written By
Anna Zombori-Suszter
How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!
While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.
Legacy Article
You are viewing an article from our legacy "FastTrack"
publication program, made available for informational purposes. Articles
in this program were published without a requirement for independent
editing or verification and are provided"as is" without
guarantee.
Before using any information from this article, independently verify its
suitability for your situation and project.
Issue
- When a Spring MVC portlet is trying to call a Service Builder service, there are
java.lang.ClassCastExceptions in the logs. For example:
ERROR [http-nio-8080-exec-5][DispatcherPortlet:428] Could not complete request
java.lang.ClassCastException: com.sun.proxy.$Proxy1205 cannot be cast to sample.service.service.SampleLocalService
at sample.service.service.SampleLocalServiceUtil.getService(SampleLocalServiceUtil.java:367)
at sample.service.service.SampleLocalServiceUtil.getSamplesCount(SampleLocalServiceUtil.java:347)
at sample.springmvc.portlet1.controller.UserController.submitApplicant(UserController.java:91)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
at com.liferay.portletmvc4spring.mvc.method.annotation.PortletInvocableHandlerMethod.invokeAndHandle(PortletInvocableHandlerMethod.java:100)
at com.liferay.portletmvc4spring.mvc.method.annotation.PortletRequestMappingHandlerAdapter.invokeHandlerMethod(PortletRequestMappingHandlerAdapter.java:1042)
at com.liferay.portletmvc4spring.mvc.method.annotation.PortletRequestMappingHandlerAdapter.doHandle(PortletRequestMappingHandlerAdapter.java:586)
at com.liferay.portletmvc4spring.mvc.method.annotation.PortletRequestMappingHandlerAdapter.doHandle(PortletRequestMappingHandlerAdapter.java:535)
at com.liferay.portletmvc4spring.mvc.method.annotation.PortletRequestMappingHandlerAdapter.handleActionInternal(PortletRequestMappingHandlerAdapter.java:601)
at com.liferay.portletmvc4spring.mvc.method.AbstractPortletHandlerMethodAdapter.handleAction(AbstractPortletHandlerMethodAdapter.java:55)
at com.liferay.portletmvc4spring.DispatcherPortlet.doActionService(DispatcherPortlet.java:462)
at com.liferay.portletmvc4spring.FrameworkPortlet.processRequest(FrameworkPortlet.java:692)
at com.liferay.portletmvc4spring.FrameworkPortlet.processAction(FrameworkPortlet.java:232)
...
Resolution
- In this case, the Service Builder module's API is added as a dependency in the Spring MVC Portlet which makes the API's jar to be included in the built WAR's WEB-INF/lib folder and this results in the above error.
- In order to make sure that the jar is not included in the WAR itself, the following property should be added to the portal-ext.properties file:
module.framework.web.generator.excluded.paths=<CURRENT EXCLUSIONS>,\
WEB-INF/lib/{api-jar}
Did this article resolve your issue ?