0
votes

I try to deploy a simple spring portlet in ext (I can't use Plugins SDK...) on Liferay 5.2.3

My 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
  • spring-webmvc.jar
  • spring-webmvc-portlet.jar
  • spring.jar
  • standard.jar

ext-web/docroot/html/portlet/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-web/docroot/html/portlet/ext/springmvc/index.jsp

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

ext-web/docroot/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/docroot/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/docroot/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> 

Are there some mistakes?

I get this error, when I try to deploy:

 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

Hope anybody can help me...

2

2 Answers

1
votes

You are using the wrong flavour of Spring mvc here. You are talking to the servlet API in your code, but you should be talking to the Portlet API. Luckily, spring has a specialized version of spring mvc, called spring portlet mvc.

To get a feel for it, read this: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/portlet.html

0
votes

Checkout this blog- How to setup Liferay+SpringMVC?

You will find how to setup a Liferay+SpringMVC portlet.