将简单的Spring MVC Portlet部署到Liferay 5.2.3

时间:2010-04-09 14:06:40

标签: liferay

我尝试在Liferay 5.2.3上部署一个简单的spring portlet(我不能使用Plugins SDK ...)

我的portlet:

EXT-IMPL / SRC:

package:com.ext.portlet.springmvc

HelloWorldController.java

package com.ext.portlet.springmvc;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

public class HelloWorldController implements Controller {

    public ModelAndView handleRequest(HttpServletRequest request, 
        HttpServletResponse response) throws ServletException, IOException {

        String aMessage = "Hello World MVC!";
        ModelAndView modelAndView = new ModelAndView("hello_world");
        modelAndView.addObject("message", aMessage);

        return modelAndView;
    }
}

EXT-LIB:

  • jstr.jar
  • 弹簧webmvc.jar
  • 弹簧webmvc-portlet.jar
  • 的spring.jar
  • standard.jar

EXT-网/文档根/ HTML /门户/ EXT /用SpringMVC / hello_world.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<body>
    <p>This is my message: ${message}</p>
</body>
</html>

EXT-网/文档根/ HTML /门户/ EXT /用SpringMVC / index.jsp的

<html>
    <body>
        <p>Hi</p>
    </body>
</html>

EXT-网/文档根/ WEB-INF /用SpringMVC-servlet.xml中

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

    <bean name="/hello_world.html" class="com.ext.portlet.springmvc.HelloWorldController"/>

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/jsp/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

</beans>

EXT-网/文档根/ WEB-INF / portlet的ext.xml

<portlet>
    <portlet-name>springmvc</portlet-name>
    <portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
    <supports>
        <mime-type>text/html</mime-type>
        <portlet-mode>view</portlet-mode>
    </supports>
    <portlet-info>
        <title>Simple JSP Portlet</title>
    </portlet-info>
    <security-role-ref>
        <role-name>power-user</role-name>
    </security-role-ref>
    <security-role-ref>
        <role-name>user</role-name>
    </security-role-ref>
</portlet> 

EXT-网/文档根/ WEB-INF / web.xml中

<?xml version="1.0"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">

    <servlet>
        <servlet-name>springmvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>
          jsp/index.jsp
        </welcome-file>
    </welcome-file-list>
</web-app> 

是否有错误?

当我尝试部署时,我收到此错误:

 Website OC4J 10g (10.1.3) Default Web Site definiert ist. Error creating bean w
ith name 'com.liferay.portal.kernel.captcha.CaptchaUtil' defined in class path r
esource [META-INF/util-spring.xml]: Cannot create inner bean 'com.liferay.portal
.captcha.CaptchaImpl#1424b7b' of type [com.liferay.portal.captcha.CaptchaImpl] w
hile setting bean property 'captcha'; nested exception is org.springframework.be
ans.factory.BeanCreationException: Error creating bean with name 'com.liferay.po
rtal.captcha.CaptchaImpl#1424b7b' defined in class path resource [META-INF/util-
spring.xml]: Instantiation of bean failed; nested exception is org.springframewo
rk.beans.BeanInstantiationException: Could not instantiate bean class [com.lifer
ay.portal.captcha.CaptchaImpl]: Constructor threw exception; nested exception is
 java.lang.NullPointerException

希望有人能帮助我......

2 个答案:

答案 0 :(得分:1)

你在这里使用的是错误的Spring mvc。您正在与代码中的servlet API进行通信,但您应该与Portlet API进行通信。幸运的是,spring有一个专门版本的spring mvc,叫做spring portlet mvc。

要了解它,请阅读:http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/portlet.html

答案 1 :(得分:0)

Checkout this blog- How to setup Liferay+SpringMVC?

您将找到如何设置Liferay + SpringMVC portlet。