2

我正在 liferay 中开发基于 Spring MVC 的 portlet。基本上我想在一个 liferay 项目本身中配置和维护 2 或 3 个 portlet。一些人可以指导我进行相同的配置。就像 portlet.xml、spring config 和 web config 的配置代码(如果需要)。我只需要分别为我的所有 portlet 配置一个默认控制器,这样每个 portlet 都会进入不同的登录页面。

有人知道如何配置这些 portlet 吗?任何建议都会有所帮助:D

提前致谢。

4

1 回答 1

4

是的,可以在单个插件项目中配置多个 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

于 2014-05-25T10:01:45.580 回答