【问题标题】:Liferay : Configuring Multiple Spring MVC Portlets in one liferay plugin projectLiferay : 在一个 liferay 插件项目中配置多个 Spring MVC Portlet
【发布时间】:2014-05-25 09:12:05
【问题描述】:

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

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

提前致谢。

【问题讨论】:

    标签: java spring-mvc liferay-6 spring-portlet-mvc


    【解决方案1】:

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

    您可以在此文件中指定多个 条目。对于 spring portlet,您应该指定 如下。

        <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 中并在此文件中指定它。

    在 liferay-portlet.xml 中

    甚至这个文件也包含多个 标签。

    在您的 portlet 控制器类中

    添加注释以指定控制器并映射到 portlet 模式。您可以在此处查看 spring 文档中提供的各种其他映射。

    @控制器

    @RequestMapping(value = PortletModeVal.VIEW)

    公共类 MyPortletControll 实现 PortletConfigAware

    【讨论】:

    • 太棒了。很高兴知道它有帮助。
    猜你喜欢
    • 2015-02-14
    • 1970-01-01
    • 1970-01-01
    • 2015-07-21
    • 1970-01-01
    • 2019-02-16
    • 2017-01-30
    • 1970-01-01
    • 2013-06-17
    相关资源
    最近更新 更多