掲示板

How to locate a spring defined bean in another portlet

9年前 に Clark Cui によって更新されました。

How to locate a spring defined bean in another portlet

New Member 投稿: 17 参加年月日: 10/02/15 最新の投稿
I have a spring bean defined in a Spring Portlet A. My question is how to use portlet bean locator to locate this bean in another Portlet B. Is it possible, cause the below line didn't work for me.

MyBean myBean = (MyBean)PortletBeanLocatorUtil.locate("PortletA-portlet", MyBean.class.getName());


PS: i declare the ContextLoaderListener in Portlet A web.xml and use a contextConfigLocation to set which context file to load, and this bean is defined in the context file.
9年前 に Martin Jonik によって更新されました。

RE: How to locate a spring defined bean in another portlet

Junior Member 投稿: 69 参加年月日: 12/08/14 最新の投稿
Did you find a solution for that?
thumbnail
9年前 に David H Nebinger によって更新されました。

RE: How to locate a spring defined bean in another portlet

Liferay Legend 投稿: 14914 参加年月日: 06/09/02 最新の投稿
Won't work. The PortletBeanLocator does not expose all spring beans, only beans specifically registered w/ the bean locator service. Besides, you're crossing the class loader boundary so just getting the bean will often not be enough, you'd have to religiously be using interfaces vs implementation classes, the interface classes must match exactly in both wars (i.e. what service builder does), ...

Trust me, don't try to do what you're thinking about doing, it will be nothing but headaches.

If you must share spring beans, put the plugins in the same war file or use ServiceBuilder to handle all of the web app boundary crossing for you (SB doesn't need to be just for database services, check out this post.