是的,可以在单个插件项目中配置多个 spring portlet,以使单个 .war 文件包含多个 portlet。
在 web.xml 中
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>view-servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>view-servlet</servlet-name>
<url-pattern>/WEB-INF/servlet/view</url-pattern>
</servlet-mapping>
在 applicationContext.xml
您可以在此处为所有 portlet 指定通用 bean 配置。
<context:annotation-config />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="cache" value="false"/>
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/jsp/"/>
<property name="suffix" value=".jsp"/>
<property name="contentType" value="text/html; charset=UTF-8" />
</bean>
在 portlet.xml 中
您可以在此文件中指定多个 <portlet> 条目。对于 spring portlet,您应该指定 <portlet-class> 和 <init-param>,如下所示。
<portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
<init-param>
<name>contextConfigLocation</name>
<value>classpath:myportlet-context.xml</value>
</init-param>
在 myportlet-context.xml 中
将您的 portlet 控制器类放在 my.portlet.package 中并在此文件中指定它。
<context:component-scan base-package="my.portlet.package" />
在 liferay-portlet.xml
甚至这个文件也包含多个 <portlet> 标记。
在您的 portlet 控制器类中
添加注释以指定控制器并映射到 portlet 模式。您可以在此处查看 spring 文档中提供的各种其他映射。
@控制器
@RequestMapping(值 = PortletModeVal.VIEW)
公共类 MyPortletControll 实现 PortletConfigAware