Pregunta

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.

¿Fue útil?

Solución 2

Problem solved!

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.

Otros consejos

First I would suggest that you have each portlet (controllers) in separate packages.

For each portlet you should have spring xml file named after "portlet-name" from portlet.xml So if you have <portlet-name>my-first-portlet</portlet-name> you shoud have myfirstportlet-portlet.xml, in WEB-INF, that has component-scan element.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top