Liferay DXP の Spring MVC ポートレットから Service Builder モジュールにアクセスする
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
learn-legacy-article-disclaimer-text
問題
Spring MVC ポートレットが Service Builder サービスを呼び出そうとすると、ログに java.lang.ClassCastExceptionが記録されます。 例:
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) ...
Environment
DXP 7.0+
解決策
この場合、Service Builder モジュールの API が Spring MVC ポートレットの依存関係として追加され、ビルドされた WAR の WEB-INF/lib フォルダーに API の jar が含まれるようになり、上記のエラーが発生します。
jar が WAR 自体に含まれていないことを確認するには、次のプロパティを portal-ext.properties ファイルに追加する必要があります。