I have a WAR file containing two portlets with their dedicated controllers.
How do I have to configure it that all controllers (handler methods) will be found when I start Liferay/invoke the page containing the two portlets?
In portlet.xml both portlets can be found both having
<portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
.
In spring-mvc-portlet.xml I use <context:component-scan base-package="com.foo.bar" />
.
Both controllers shall have a default handler method annotated with @RenderMapping. The controllers are both annotsated with @RequestMapping("VIEW") at type level.
What presently happens is that only the default handler method from controller A (the first one defined in portlet.xml) is invoked.
I solved the problem and this way works for me:
I had to put each controller into its own package. To make Liferay aware of this I had to configure portlet.xml
in a way to give each portlet which is listed a dedicated context configuration. Thus, I copied the <myPortlet>-portlet.xml
,
renamed it properly to <myOtherPortlet>-portlet.xml
and put this name into the
contextConfigParam <init-param>
element in portlet.xml.
Within the context config files I had to modify the context:component-scan element as follows to exclude the other controller to be
disregarded for this controller. For example, in the context configuration XML file for my ListController I have to exclude the
ImportController this way:
<context:component-scan base-package="com.foo.bar" use-default-filters="true">
<context:exclude-filter type="assignable" expression="com.foo.bar.importer.portlet.ImportController"/>
</context:component-scan>
...and in the context configuration XML file for the ImportController I have to exclude the ListController accordingly.