- 浏览: 606387 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (263)
- 默认类别 (0)
- STRUTS HIBERNATE (2)
- STRUTS SPRING HIBERNATE (18)
- SOA/WEB service (8)
- PORTAL (3)
- 想法和设计思想 (17)
- SMARTEAM 二次开发 (0)
- ACTIVEBPEL (0)
- ERP (0)
- EAI (0)
- 甲醇汽油 (0)
- webwork freemarker spring hibernate (1)
- 工作流技术研究 (1)
- ROR (5)
- 搜索引擎 (7)
- 3.非技术区 (0)
- 1.网站首页原创Java技术区(对首页文章的要求: 原创、高质量、经过认真思考并精心写作。BlogJava管理团队会对首页的文章进行管理。) (2)
- 2.Java新手区 (2)
- 4.其他技术区 (0)
- ESB (1)
- Petals ESB (6)
- 手机开发 (1)
- docker dedecms (1)
最新评论
-
w630636065:
楼主,期待后续!!!!!!!!
生成文本聚类java实现 (2) -
zilong513:
十分感谢楼主,期待后续。
生成文本聚类java实现 (2) -
qqgoodluck:
可否介绍一下您的选型依据,包括Petal ESB与MULE等E ...
Petals ESB 简介 -
jackiee_cn:
写的比较清楚,学习了
Petals ESB 集群实战 -
忙两夜:
你好,能发一下源代码吗
抓取口碑网店铺资料
本文使用spring集成hibernate完成一个liferay portlet的开发,做为plugin的方式部署到liferay容器当中。提供源代码下载。
版本约束:
Spring 3.0 及以上
Hiberante 3.5
Liferay 6.0及以上
构建基制:
Ant
Maven
知识点描述:
使用Hiberante+jndi的方式,否则使用Hiberante+jdbc的话,在liferay当中部署不成功,然后再集成Spring,最前端使用GenericPortlet。
开发配置:
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"> <display-name>AntBee Portlet</display-name> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>/WEB-INF/classes/log4j.properties</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app>
Spring的配置文件:applicationContext.xml,放在\WEB-INF\applicationContext.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" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd "> <aop:aspectj-autoproxy /> <context:component-scan base-package="com.antbee.portlet" /> <jee:jndi-lookup jndi-name="java:comp/env/jdbc/myportalDB" id="dataSource" /> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="annotatedClasses"> <list> <value>com.antbee.portlet.domain.MonitorItem</value> <value>com.antbee.portlet.domain.SearchResult4Db</value> </list> </property> </bean> <tx:annotation-driven transaction-manager="txManager" /> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="loggingAspect" class="com.antbee.portlet.base.LoggingAspect" /> </beans>
针对Liferay Portlet的几个配置文件:portlet.xml,放在目录:WEB-INF\portlet.xml
<?xml version="1.0" encoding="UTF-8"?> <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"> <portlet> <portlet-name>resultForNews</portlet-name> <portlet-class>com.antbee.portlet.base.SearchResultPortlet</portlet-class> <expiration-cache>1000</expiration-cache> <cache-scope>private</cache-scope> <supports> <mime-type>text/html</mime-type> <portlet-mode>view</portlet-mode> </supports> <resource-bundle>content.Language-ext</resource-bundle> <portlet-info> <title>安特比软件-Portlet演示</title> </portlet-info> </portlet> </portlet-app>
接上面,同样是portlet的配置文件:liferay-display.xml,放在目录WEB-INF\liferay-display.xml
<?xml version="1.0"?> <!DOCTYPE display PUBLIC "-//Liferay//DTD Display 6.0.0//EN" "http://www.liferay.com/dtd/liferay-display_6_0_0.dtd"> <display> <category name="antbee.portlet.function"> <portlet id="resultForNews" /> </category> </display>
接上面,同样是portlet的配置文件:liferay-portlet.xml,放在目录WEB-INF\liferay-portlet.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 6.0.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_6_0_0.dtd"> <liferay-portlet-app> <portlet> <portlet-name>resultForNews</portlet-name> <instanceable>true</instanceable> <remoteable>true</remoteable> <header-portlet-css>/css/bookCatalog.css</header-portlet-css> <header-portlet-javascript>/js/bookCatalog.js</header-portlet-javascript> </portlet> </liferay-portlet-app>
前端继承的GenericPortlet的SearchResultPortlet.java
package com.antbee.portlet.base; import java.io.IOException; import java.util.Enumeration; import java.util.List; import java.util.Map; import javax.portlet.GenericPortlet; import javax.portlet.PortalContext; import javax.portlet.PortletException; import javax.portlet.PortletMode; import javax.portlet.PortletRequest; import javax.portlet.RenderMode; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import javax.portlet.WindowState; import org.apache.log4j.Logger; import org.springframework.context.ApplicationContext; import org.springframework.web.portlet.context.PortletApplicationContextUtils; import com.antbee.portlet.service.SearchResultService; import com.antbee.portlet.utils.Constants; /** * * @author Weiya * */ public class SearchResultPortlet extends GenericPortlet { private Logger logger = Logger.getLogger(SearchResultPortlet.class); private static SearchResultService searchResultService; public void init() { searchResultService = getSearchResultService(); } public SearchResultService getSearchResultService() { ApplicationContext springCtx = PortletApplicationContextUtils.getWebApplicationContext(getPortletContext()); return (SearchResultService)springCtx.getBean("searchResultService"); } @RenderMode(name = "VIEW") public void showSearchResult(RenderRequest request, RenderResponse response) throws IOException, PortletException { logger.info("Inside showSearchResult method"); PortalContext context = request.getPortalContext(); printSupportedPortletModes(context); printSupportedWindowStates(context); Map userAttributeMap = (Map) request .getAttribute(PortletRequest.USER_INFO); String firstName = ""; String lastName = ""; if (userAttributeMap != null) { firstName = (String) userAttributeMap.get("user.name.given"); lastName = (String) userAttributeMap.get("user.name.family"); // --set firstName and lastName in request so that JSP can pick // --from the request request.setAttribute("firstName", firstName); request.setAttribute("lastName", lastName); } String jspPage = "home.jsp"; // Got Data List results = searchResultService.getKeyWordByMonitorItem(3); request.setAttribute("results", results); getPortletContext().getRequestDispatcher( response.encodeURL(Constants.PATH_TO_JSP_FUNCTION_PAGE + jspPage)) .include(request, response); } //-- Print supported portlet modes by the portal server private void printSupportedPortletModes(PortalContext context) { // -- supported portlet modes by the portal server Enumeration<PortletMode> portletModes = context .getSupportedPortletModes(); while (portletModes.hasMoreElements()) { PortletMode mode = portletModes.nextElement(); logger.info("Support portlet mode " + mode.toString()); } } //-- prints support window states by the portal server private void printSupportedWindowStates(PortalContext context) { // -- supported window states by the portal server Enumeration<WindowState> windowStates = context .getSupportedWindowStates(); while (windowStates.hasMoreElements()) { WindowState windowState = windowStates.nextElement(); logger.info("Support window state " + windowState.toString()); } } }
还有构建脚本:build.xml
<?xml version="1.0"?> <!-- define the project --> <project name="antbeePortlet" default="build" basedir="."> <!-- define project properties --> <property name="compiler" value="modern" /> <property name="fork" value="no" /> <property name="verbose" value="no" /> <property name="debug" value="on" /> <property name="optimize" value="on" /> <property name="deprecation" value="on" /> <property name="target" value="1.5" /> <property name="source" value="1.5" /> <property file="build.properties" /> <property environment="env" /> <!-- define properties to refer to directories in the project --> <property name="webinf.dir" value="WEB-INF" /> <property name="webinf.lib.dir" value="WEB-INF/lib" /> <property name="lib.dir" value="lib" /> <property name="src.dir" value="src" /> <property name="test.dir" value="test" /> <property name="build.dir" value="build" /> <property name="webinf.classes.dir" value="${webinf.dir}/classes" /> <property name="webinf.classes.content.dir" value="${webinf.dir}/classes/content" /> <property name="web.xml" value="${webinf.dir}/web.xml" /> <fileset id="webapp.libs" dir="${webinf.lib.dir}"> <include name="*.jar" /> </fileset> <fileset id="libs" dir="${lib.dir}"> <include name="*.jar" /> </fileset> <path id="class.path"> <pathelement path="${webinf.classes.dir}" /> <fileset refid="webapp.libs" /> <fileset refid="libs" /> </path> <pathconvert pathsep=":" property="class.path" refid="class.path" /> <fileset id="war.files" dir="."> <include name="${webinf.dir}/**" /> <exclude name="${webinf.dir}/Language-ext*.properties" /> <exclude name="${webinf.dir}/ValidationMessages.properties" /> <include name="images/**" /> <include name="css/**" /> <include name="js/**" /> <exclude name="${web.xml}" /> </fileset> <!-- compile target to compile the sources --> <target name="compile"> <mkdir dir="${webinf.classes.dir}" /> <!-- Content directory contains Liferay resource bundle--> <mkdir dir="${webinf.classes.content.dir}" /> <javac srcdir="${src.dir}:${test.dir}" destdir="${webinf.classes.dir}" fork="${fork}" verbose="${verbose}" deprecation="${deprecation}" debug="${debug}" optimize="${optimize}" compiler="${compiler}" target="${target}" source="${source}"> <classpath refid="class.path" /> </javac> <copy todir="${webinf.classes.dir}" preservelastmodified="true"> <fileset dir="${src.dir}"> <include name="**/*.properties" /> <include name="**/*.xml" /> </fileset> </copy> <copy todir="${webinf.classes.content.dir}"> <fileset dir="${webinf.dir}"> <include name="Language-ext*.properties" /> </fileset> </copy> </target> <!-- target to create the project WAR file --> <target name="build" depends="clean,compile"> <mkdir dir="${build.dir}" /> <war destfile="${build.dir}/antbeePortlet.war" webxml="${web.xml}"> <fileset refid="war.files" /> </war> <copy todir="${liferay.portal.home}/deploy"> <fileset dir="${build.dir}"> <include name="**/*.war" /> </fileset> </copy> </target> <!-- target to clean up all files created by various tasks --> <target name="clean"> <delete quiet="true" includeemptydirs="true"> <fileset dir="${webinf.classes.dir}" includes="**/*" /> <fileset dir="${build.dir}" /> <fileset dir="${work.dir}" /> </delete> </target> </project>
另外一个是SVN的构建脚本pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>antbee</groupId> <artifactId>antbeePortlet</artifactId> <packaging>war</packaging> <version>1.0</version> <repositories> <repository> <id>JBoss Repository</id> <url>http://repository.jboss.com/maven2</url> </repository> </repositories> <build> <sourceDirectory>${project.basedir}/src</sourceDirectory> <outputDirectory>${project.basedir}/target/classes</outputDirectory> <resources> <resource> <targetPath>content</targetPath> <directory>WEB-INF</directory> <includes> <include>Language-ext.properties</include> </includes> </resource> </resources> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.1-alpha-2</version> <configuration> <webResources> <resource> <directory>css</directory> <targetPath>css</targetPath> </resource> <resource> <directory>js</directory> <targetPath>js</targetPath> </resource> <resource> <directory>images</directory> <targetPath>images</targetPath> </resource> <resource> <directory>WEB-INF/jsp/</directory> <targetPath>WEB-INF/jsp</targetPath> </resource> <resource> <directory>WEB-INF</directory> <targetPath>WEB-INF</targetPath> <includes> <include>**/*.xml</include> </includes> <excludes> <exclude>Language-ext.properties</exclude> </excludes> </resource> </webResources> <webXml>${project.basedir}/WEB-INF/web.xml</webXml> </configuration> </plugin> </plugins> </pluginManagement> </build> <dependencies> <dependency> <groupId>javax.portlet</groupId> <artifactId>portlet-api</artifactId> <version>2.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.14</version> </dependency> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.2.1</version> </dependency> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.4</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>3.5.0-Final</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-annotations</artifactId> <version>3.5.0-Final</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-asm</artifactId> <version>3.0.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>3.0.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>3.0.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>3.0.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <version>3.0.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc-portlet</artifactId> <version>3.0.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>3.0.0.RELEASE</version> </dependency> <dependency> <groupId>aopalliance</groupId> <artifactId>aopalliance</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.6.8</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.6.8</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>3.0.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>3.0.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>3.0.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>3.0.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>3.0.0.RELEASE</version> <scope>test</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.4</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.5.6</version> </dependency> <dependency> <groupId>org.hibernate.javax.persistence</groupId> <artifactId>hibernate-jpa-2.0-api</artifactId> <version>1.0.0.Final</version> </dependency> <dependency> <groupId>javassist</groupId> <artifactId>javassist</artifactId> <version>3.9.0.GA</version> </dependency> </dependencies> </project>
哈哈。如果完成项目后,可以通过:
ANT脚本: ant clean build
MAVEN脚本:mvn clean install构建项目
在部署到liferay时,要创建jndi的连接方式,如下是我的创建过程和脚本:(目标是TOMCAT服务器)
Add <Resource> element in server.xml, inside <GlobalNamingResources> element.
<GlobalNamingResources> .. <Resource name="jdbc/myportalDB" auth="Container" type="javax.sql.DataSource" username="root" password="root" driverClassName="com.mysql.jdbc.Driver" factory="org.apache.commons.dbcp.BasicDataSourceFactory" url="jdbc:mysql://localhost/myportaldb?useUnicode=true&" maxActive="5" maxIdle="2"/> .. </GlobalNamingResources>
Add <ResourceLink> element in context.xml file, inside <Context> element.
<Context> .... <ResourceLink name="jdbc/myportalDB" global="jdbc/myportalDB" type="javax.sql.DataSource"/> .... </Context>
重新启动,enjoy it!
不买关子,提供代码让大家下载,如果有什么不明白的,请留言。(eclipse项目,可以直接导入)
下载代码当中去掉了jar,如下是抓图:
相关推荐
spring portletMVC
在IT领域,特别是企业级应用开发中,Liferay作为一个强大的企业门户平台,提供了丰富的功能和服务,其中Liferay Portlet的开发是构建定制化企业应用的关键技术之一。本文将基于提供的文件信息,深入解析Liferay ...
Liferay Portlet开发文档是一份全面介绍Liferay Portlet开发的指南,内容涵盖了Portal的概念、Portlet的定义以及JSR 286(Java Specification Request 286)规范。文档强调了Liferay作为一款开源企业级门户网站解决...
一旦portlet开发完成,可以通过部署war文件到Liferay Server来发布portlet。Liferay会自动识别并安装portlet。 7. **Liferay Service Builder** 用于创建和操作Liferay的数据模型,自动生成服务接口、实现、DAO和...
本指南将重点介绍使用Liferay Plugin SDK进行Portlet插件开发的方法。 #### 三、创建Portlet插件工程 ##### 1. 前置准备 - **安装Liferay Eclipse 插件**:首先需要安装Liferay的Eclipse插件或直接使用Liferay...
总的来说,Liferay基于Struts2+Hibernate+Spring的架构为开发者提供了一个强大且灵活的开发环境,允许创建功能丰富的portlet和门户应用,同时通过Spring的整合能力,使得各组件协同工作,提升了整体的开发效率和应用...
《Liferay Portlet开发参考手册》是温兵先生编著的一本专为开发者设计的指南,旨在帮助读者深入了解和熟练掌握Liferay Portal平台上的Portlet开发技术。Liferay Portal是一款开源的企业级内容管理平台,而Portlet是...
liferay开发文档.pdf Liferay 是一个基于Java的开源企业门户平台,...这些知识点涵盖了Liferay 的安装、配置、Portlet开发、术语与缩写解释、版本历史等方面,旨在帮助读者更好地理解Liferay 的工作原理和开发技术。
【描述】提到的"struts2+spring2.5+hibernate3.3"是一个经典的Java企业级应用开发框架组合,也被称为SSH框架。Struts2是一个MVC(Model-View-Controller)框架,用于处理HTTP请求并管理业务逻辑;Spring2.5提供了...
liferay portlet例子 liferay portlet例子
开发者可以通过这个案例学习如何在Liferay中创建portlet,然后引入Struts2进行前端请求处理,利用Spring进行业务逻辑和服务管理,以及使用iBatis进行数据库操作。此外,案例可能还包括了相应的配置文件,如struts....
"Liferay Portlet Demo"是一个示例项目,旨在展示如何在Liferay环境中开发、部署和使用portlet。这个项目通常包含一系列的源代码、配置文件以及必要的资源,用于帮助开发者理解和实践portlet开发。 【描述】:...
总结,Spring Portlet MVC是Spring框架与portlet技术的完美结合,它为portlet开发提供了强大的MVC支持,使开发者能够构建高效、灵活的portlet应用。通过深入理解和实践Spring Portlet MVC的相关知识点,开发者可以更...
开发这样一个组件需要对Liferay Portlet API、JSP以及Liferay的权限和部署流程有深入的理解。通过message-portlet这个压缩包,我们可以期待找到所有实现这些功能的源代码、配置文件和其他资源。
- **文档**:如“Liferay-Portlet-SDK 5.2.3操作说明.ppt”文件,它详细介绍了SDK的使用方法,包括portlet的开发流程、配置、部署以及调试技巧。这份文档通常会涵盖portlet生命周期、portlet上下文、渲染和事件处理...
通过深入学习和理解这个项目,开发者可以掌握如何在Liferay中创建和部署Spring Portlet,了解portlet的生命周期和交互方式,以及Spring框架在portlet开发中的应用。同时,如果进一步集成Hibernate,还可以学习到如何...
在IT行业中,开发环境的建立是开发者日常工作中的一项重要任务,尤其对于进行企业级应用开发时,如Liferay这样的开源门户平台。本篇将详细阐述如何在Eclipse集成开发环境中结合DB2数据库来构建Liferay的扩展开发环境...
开发Liferay Portlet时,可以选择继承Liferay提供的基类,如com.liferay.portlet.LiferayPortlet,或者直接继承JSR标准的javax.portlet.GenericPortlet。 在部署Liferay应用到一个新的Tomcat服务器时,需要注意一些...
《Liferay Portlet 开发——全面指南》:深入解析与实战技巧 本书旨在为开发者提供一份详尽的Liferay Portlet开发指南,涵盖从基础知识到实际应用的全面内容。Liferay是一款开源的企业级门户平台,它支持高度定制化...
7. **部署和测试**:完成开发后,portlet需要打包成WAR文件并部署到Liferay服务器上。在Liferay控制台中,你可以添加新的portlet并将其拖放到门户布局上进行测试。 通过上述步骤,我们可以理解如何利用Struts1的MVC...