当前位置: 首页 > 工具软件 > Light Portal > 使用案例 >

light-portal分析(三)集成spring mvc portlet controller开发的portlet

邢永安
2023-12-01
light-portal分析(三)集成spring mvc portlet controller开发的portlet

将easyportlet打成jar包放置到web-inf/lib下
修改配置文件portlet.xml,增加如下内容:
<portlet>
<portlet-name>springPortlet</portlet-name>
<portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
<init-param>
<name>contextConfigLocation</name>
<value>classpath:/applicationContext-easyportlet.xml</value>
</init-param>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
<portlet-mode>help</portlet-mode>
</supports>
<resource-bundle>resourceBundle</resource-bundle>
<portlet-info>
<title>easyportlet</title>
</portlet-info>
</portlet>
web.xml增加配置如下:
<!-- 设定ViewRendererServlet -->
<servlet>
<servlet-name>ViewRendererServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>ViewRendererServlet</servlet-name>
<url-pattern>/WEB-INF/servlet/view</url-pattern>
</servlet-mapping>
pom.xml增加jar包如下:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc-portlet</artifactId>
<version>2.5.6</version>
</dependency>

试着启动应用,报错如下:

2009-09-16 15:17:17,187 ERROR [org.springframework.web.portlet.DispatcherPortlet] - <Context initialization failed>
org.springframework.beans.factory.BeanDefinitionStoreException: Parser configuration exception parsing XML from class path resource [applicationContext-easyportlet.xml]; nested exception is javax.xml.parsers.ParserConfigurationException: Unable to validate using XSD: Your JAXP provider [org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@23c7f5] does not support XML Schema. Are you running on Java 1.4 with Apache Crimson? Upgrade to Apache Xerces (or Java 1.5) for full XSD support.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)

晕,原来是lib下面的包xerces-1.4.0.jar导致的,版本过低,在pom.xml中增加:
<dependency>
<groupId>xerces</groupId>
<artifactId>xerces</artifactId>
<version>2.2.1</version>
</dependency>

重新启动,报错如下:
2009-09-16 15:55:18,312 ERROR [org.light.portal.Servlet] - <class javax.portlet.PortletException: null>
2009-09-16 15:55:18,312 ERROR [org.light.portal.Servlet] - <class org.exolab.castor.xml.MarshalException: The following exception occured while validating field: _portletList of class: org.light.portal.portlet.config.Portlets: The field '_language' (whose xml name is 'language') is a required field of class 'org.light.portal.portlet.config.Portlet>
2009-09-16 15:55:18,312 ERROR [org.light.portal.Servlet] - <class org.exolab.castor.xml.ValidationException: The following exception occured while validating field: _portletList of class: org.light.portal.portlet.config.Portlets: The field '_language' (whose xml name is 'language') is a required field of class 'org.light.portal.portlet.config.Portlet>
2009-09-16 15:55:18,312 ERROR [org.light.portal.Servlet] - <class org.exolab.castor.xml.ValidationException: The field '_language' (whose xml name is 'language') is a required field of class 'org.light.portal.portlet.config.Portlet>

在配置中增加
<language>all</language>就可以解决这个报错问题
完整的portlet-config.xml中增加的块如下:
<portlet>
<name>springPortlet</name>
<path>/springPortlet.lp</path>
<title>Spring Demo</title>
<icon></icon>
<url />
<tag>default</tag>
<language>all</language>
<refreshMode>true</refreshMode>
<editMode>false</editMode>
<helpMode>false</helpMode>
<configMode>false</configMode>
<autoRefreshed>false</autoRefreshed>
<periodTime>0</periodTime>
<allowJS>true</allowJS>
<pageRefreshed>false</pageRefreshed>
</portlet>

拷贝easyportlet中的jsp页面到WEB-INF/portlets/easyportlet中,
启动出现如下错误:
The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved
要注意jstl和standard的版本。都统一用1.0保持一致。POM.XML修改为:
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.0.6</version>
</dependency>
1.0版本的:
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

避免<c:out 标签出现According to TLD or attribute directive in tag file, attribute value does not accept any expressions错误,可以更新为以下标签
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>


1.1版本
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
修改一下easyportlet中的jstl版本。另外将easyportlet中的applicationContext.xml中的配置都放到
applicationContext-easyportlet.xml中,并修改一下spring mvc view resolver的配置
 类似资料: