Liferay 7模块项目Spring MVC Portlet,没有处理程序发现错误,因为没有viewrendererservlet

时间:2016-08-13 05:32:46

标签: spring-mvc liferay liferay-ide liferay-7

我正在使用刀片CLI开发一个简单的spring mvc portlet。我收到错误

  

错误[http-nio-8080-exec-9] [render_portlet_jsp:131] null   org.springframework.web.portlet.NoHandlerFoundException:没有处理程序   找到portlet请求:mode' view',phase' RENDER_PHASE',   参数map [[empty]]

我不知道如何解决这个问题。我还检查了以下链接,但我不知道如何解决它。 https://issues.liferay.com/browse/LPS-63801?_ga=1.195671916.133904790.1461624186      任何帮助,将不胜感激。感谢。

请找到以下代码。

1.SpringController.java

package com.liferay.docs.mvcportlet.portlet.portlet;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.portlet.ModelAndView;
import org.springframework.web.portlet.bind.annotation.RenderMapping;
import org.springframework.web.portlet.bind.annotation.ResourceMapping;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest;
import java.io.IOException;
import java.util.Locale;
@Controller
@RequestMapping("VIEW")
@Scope("prototype")
public class SpringController {

@RenderMapping
public ModelAndView preAssess(RenderRequest renderRequest,
        RenderResponse renderResponse) {
    ModelAndView mv = new ModelAndView();
    mv.setViewName("view");
    return mv;
}
}
  1. MyMVCPortlet.java

    package com.liferay.docs.mvcportlet.portlet.portlet;
    
    import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet;
    
    import javax.portlet.Portlet;
    import javax.portlet.PortletConfig;
    import javax.portlet.PortletException;
    
    import org.osgi.framework.BundleActivator;
    import org.osgi.framework.BundleContext;
    import org.osgi.service.component.annotations.Component;
    import org.springframework.web.portlet.DispatcherPortlet;
    
    @Component(
    immediate = true,
    property = {
        "com.liferay.portlet.display-category=category.sample",
        "com.liferay.portlet.instanceable=false",
        "javax.portlet.display-name=my-mvc-portlet-project Portlet",
        "javax.portlet.init-param.view-template=/view.jsp",
        "javax.portlet.init-param.contextConfigLocation=/META-INF/spring-portlet.xml",
        "javax.portlet.resource-bundle=content.Language",
        "javax.portlet.security-role-ref=power-user,user",
    },
    service = Portlet.class
    )
     public class MyMvcPortlet extends DispatcherPortlet  {
    
    @Override
        public void init(PortletConfig config) throws PortletException {
            super.init(config);
        }
    
    
    }   
    
  2. 弹簧的portlet.xml

      <?xml version="1.0"?>
    
      <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns:p="http://www.springframework.org/schema/p"
      xmlns:tx="http://www.springframework.org/schema/tx"   xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="
            http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
            http://www.springframework.org/schema/tx 
            http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context- 3.2.xsd">
     <context:component-scan base- package="com.liferay.docs.mvcportlet.portlet.portlet" />
     <bean id="viewResolver"
     class="org.springframework.web.servlet.view.InternalResourceViewResolver">
         <property name="cache" value="true" />
         <property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView" />
         <property name="prefix" value="/views/" />
         <property name="suffix" value=".jsp" />
         </bean>
         <bean
     class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
          id="messageSource" p:fallbackToSystemLocale="true">
          <property name="defaultEncoding" value="UTF-8" />
          <!-- NOTE: cacheSeconds enable auto-reloading of properties. To turn off, 
             use "-1" -->
         <property name="cacheSeconds" value="-1" />
         <property name="basenames">
             <list>
                <value>content.languages</value>
             </list>
           </property>
       </bean>
       <bean id="localeChangeInterceptor"
               class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
         <property name="paramName" value="lang" />
       </bean>
    
        <bean id="localeResolver"
          class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
          <property name="defaultLocale" value="en" />
         </bean>
    
         <bean id="handlerMapping"
      class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMap ping">
            <property name="interceptors">
           <ref bean="localeChangeInterceptor" />
            </property>
         </bean>
        </beans>
    
  3. 的build.gradle

    buildscript {
        dependencies {
            classpath group: "com.liferay", name: "com.liferay.gradle.plugins", version: "1.0.369"
        }
    
        repositories {
            mavenLocal()
    
            maven {
                url "https://cdn.lfrs.sl/repository.liferay.com/nexus/content/groups/public"
            }
        }
    }
    
    apply plugin: "com.liferay.plugin"
    
    def SPRING_VERSION = "4.3.2.RELEASE"
    
    
     dependencies {
        compile group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.0.0"
        compile group: "com.liferay.portal", name: "com.liferay.util.taglib", version: "2.0.0"
        compile group: "com.liferay", name: "com.liferay.portal.spring.extender", version: "2.0.0"
        compile group: "javax.portlet", name: "portlet-api", version: "2.0"
        compile group: "javax.servlet", name: "servlet-api", version: "2.5"
        compile group: "jstl", name: "jstl", version: "1.2"
        compile group: "org.osgi", name: "org.osgi.compendium", version: "5.0.0"
        compile group: 'org.osgi', name: 'org.osgi.core', version: '5.0.0'
        // https://mvnrepository.com/artifact/org.springframework/spring-webmvc-portlet
        compile group: 'org.springframework', name: 'spring-webmvc-portlet', version: "$SPRING_VERSION"
        // https://mvnrepository.com/artifact/org.springframework/spring-webmvc
        compile group: 'org.springframework', name: 'spring-webmvc', version: "$SPRING_VERSION"
        // https://mvnrepository.com/artifact/org.springframework/spring-web
        compile group: 'org.springframework', name: 'spring-web', version: "$SPRING_VERSION"
        // https://mvnrepository.com/artifact/org.springframework/spring-core
        compile group: 'org.springframework', name: 'spring-core', version: "$SPRING_VERSION"
        // https://mvnrepository.com/artifact/org.springframework/spring-context
        compile group: 'org.springframework', name: 'spring-context', version: "$SPRING_VERSION"
        // https://mvnrepository.com/artifact/org.springframework/spring-beans
        compile group: 'org.springframework', name: 'spring-beans', version: "$SPRING_VERSION"
    }
    
    
    repositories {
        mavenLocal()
    
        maven {
            url "https://cdn.lfrs.sl/repository.liferay.com/nexus/content/groups/public"
        }
    }
    
  4. /META-INF/views/view.jsp

    <%@ include file="/views/init.jsp" %>
    
    <p>
        <b><liferay-ui:message key="springmvcportlet_SpringMVCPortletmvcportlet.caption"/></b>
    </p>
    

    任何帮助都会得到赞赏。感谢。

0 个答案:

没有答案