`
lan13217
  • 浏览: 501925 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

找了一篇ibatis+spring+jsf 集成的文章

    博客分类:
  • Java
阅读更多
http://mail-archives.apache.org/mod_mbox/ibatis-user-java/200811.mbox/%3Cgei0hd$plj$1@ger.gmane.org%3E

From user-java-return-15506-apmail-ibatis-user-java-archive=ibatis.apache.org@ibatis.apache.org Sat Nov 01 16:36:49 2008
Return-Path: <user-java-return-15506-apmail-ibatis-user-java-archive=ibatis.apache.org@ibatis.apache.org>
Delivered-To: apmail-ibatis-user-java-archive@www.apache.org
Received: (qmail 39394 invoked from network); 1 Nov 2008 16:36:49 -0000
Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2)
  by minotaur.apache.org with SMTP; 1 Nov 2008 16:36:49 -0000
Received: (qmail 32133 invoked by uid 500); 1 Nov 2008 16:36:49 -0000
Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org
Received: (qmail 32119 invoked by uid 500); 1 Nov 2008 16:36:48 -0000
Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm
Precedence: bulk
List-Help: <mailto:user-java-help@ibatis.apache.org>
List-Unsubscribe: <mailto:user-java-unsubscribe@ibatis.apache.org>
List-Post: <mailto:user-java@ibatis.apache.org>
List-Id: <user-java.ibatis.apache.org>
Reply-To: user-java@ibatis.apache.org
Delivered-To: mailing list user-java@ibatis.apache.org
Received: (qmail 32108 invoked by uid 99); 1 Nov 2008 16:36:48 -0000
Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136)
    by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Nov 2008 09:36:48 -0700
X-ASF-Spam-Status: No, hits=-1.0 required=10.0
tests=RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS
X-Spam-Check-By: apache.org
Received-SPF: pass (athena.apache.org: domain of gcjiu-ibatis-user-java@m.gmane.org designates 80.91.229.2 as permitted sender)
Received: from [80.91.229.2] (HELO ciao.gmane.org) (80.91.229.2)
    by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Nov 2008 16:35:30 +0000
Received: from list by ciao.gmane.org with local (Exim 4.43)
id 1KwJSK-0006VX-Jv
for user-java@ibatis.apache.org; Sat, 01 Nov 2008 16:36:08 +0000
Received: from e176190046.adsl.alicedsl.de ([85.176.190.46])
        by main.gmane.org with esmtp (Gmexim 0.1 (Debian))
        id 1AlnuQ-0007hv-00
        for <user-java@ibatis.apache.org>; Sat, 01 Nov 2008 16:36:08 +0000
Received: from andreas.niemeyer by e176190046.adsl.alicedsl.de with local (Gmexim 0.1 (Debian))
        id 1AlnuQ-0007hv-00
        for <user-java@ibatis.apache.org>; Sat, 01 Nov 2008 16:36:08 +0000
X-Injected-Via-Gmane: http://gmane.org/
To: user-java@ibatis.apache.org
From:  Andreas Niemeyer <andreas.niemeyer@gutzmann.com>
Subject:  Re: JSF configuration with Spring?
Date:  Sat, 01 Nov 2008 17:35:57 +0100
Lines: 276
Message-ID: <gei0hd$plj$1@ger.gmane.org>
References:  <geer6d$54s$1@ger.gmane.org>
Mime-Version:  1.0
Content-Type:  text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding:  7bit
X-Complaints-To: usenet@ger.gmane.org
X-Gmane-NNTP-Posting-Host: e176190046.adsl.alicedsl.de
User-Agent: Thunderbird 2.0.0.17 (Macintosh/20080914)
In-Reply-To: <geer6d$54s$1@ger.gmane.org>
Sender: news <news@ger.gmane.org>
X-Virus-Checked: Checked by ClamAV on apache.org

Hi,

I got everything working now after a few hours investigation.


The motivation was to get a basic setup working within a portlet AND a
servlet environment with a simple implemented service layer in context
of JSF.


The promised simplicity of iBatis seemed to be ideal for the
requirements: getting a loosly coupled DAO service, model undriven and
flexible in configuration, extensibility and usage. The excellent SPRING
  support was not least the key between everything.


Therefore a small summerize at this point how to glue JSF with Spring
and iBatis.


Some links helped me:

http://ibatisnet.sourceforge.net/DevGuide.html
http://www.developersbook.com/ibatis/iBatis-tutorials/iBatis-tutorials.php
http://forum.springframework.org/showthread.php?t=19032&highlight=iBatis
http://opensource.atlassian.com/confluence/spring/display/JSR168/Home
http://svn.apache.org/repos/asf/ibatis/trunk/java/ibatis-2/ibatis-2-docs/en/iBATIS-SqlMaps-2-Tutorial_en.pdf
http://svn.apache.org/repos/asf/ibatis/trunk/java/ibatis-2/ibatis-2-docs/en/iBATIS-SqlMaps-2_en.pdf


The configuration based on facelets 1.1.14, myfaces 1.1.6, ibatis
2.3.4.726, spring-framework 2.5.5 (spring.jar, spring-webmvc.jar,
spring-webmvc-portlet.jar), the portal environment is liferay x.


Only the relevant fragments are listed below portal type is independent.

The approach was to simply call a db sequence as a first step, no
classes of properties or resultsets mapped here. (shouldn't be a problem
  anymore)


Kind regards,
Andreas


1) faces-config.xml

...

<application>
<view-handler>com.sun.facelets.FaceletPortletViewHandler</view-handler> <variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>

</application>

...


2) web.xml

...

<context-param>
  <param-name>javax.faces.application.CONFIG_FILES</param-name>
  <param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>

<context-param>
  <param-name>contextConfigLocation</param-name>
   <param-value>
    /WEB-INF/classes/applicationContext.xml
  </param-value>
</context-param>

...

<listener>   
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<listener>   
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

...


3) applicationContext.xml

...

<bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/XXX"/>
</bean>

<bean id="sqlMap"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="WEB-INF/classes/sqlmap-config.xml"/>
<property name="dataSource" ref="dataSource"/>
</bean>

<bean id="sequencesBean"
         class="com.company.portlets.xxx.galery.dao.SequenceServiceImpl">
         <property name="sqlMapClient" ref="sqlMap" />
</bean>

...

4) META-INF/context.xml

...

<Resource
        name="jdbc/XXX"
         auth="Container"
         type="javax.sql.DataSource"
         driverClassName="org.postgresql.Driver"

url="jdbc:postgresql://localhost:5432/xxx?useUnicode=true&amp;characterEncoding=UTF-8"
         username="foo"
         password="foopass"
         maxActive="100"
         maxIdle="30"
         maxWait="10000"
   />

...

5) sqlmap-config.xml

...

<sqlMapConfig>
     <settings useStatementNamespaces="true"/>
     <sqlMap resource="ibatis-sql/sequences.xml"/>
</sqlMapConfig>

...

6) sequences.xml

...

<sqlMap namespace="sequences">
   <select id="getUploadSequence" resultClass="long">
     select nextval('galery_s_upload_id')
   </select>
</sqlMap>

...

7) ISequenceService class

package com.company.portlets.xxx.galery.dao;

public interface ISequenceService {
public long getUploadSequence() throws Exception ;
}


8) SequenceServiceImpl class

package com.company.portlets.xxx.galery.dao;

import com.ibatis.sqlmap.client.SqlMapClient;

public class SequenceServiceImpl implements ISequenceService {

protected SqlMapClient sqlMap = null;

     public void setSqlMapClient(SqlMapClient sqlMap) {
         this.sqlMap = sqlMap;
     }

     public long getUploadSequence() throws Exception {
         return (Long)sqlMap.queryForObject("sequences.getUploadSequence");
     }
}


9) a JSF bean class

...

import org.springframework.context.ApplicationContext;
import com.company.portlets.xxx.galery.dao.ISequenceService;

...

public long getServletuploadid() {

  ...
  long id_seq;

  ApplicationContext ctx = PortletJSFUtil.getApplicationContext();
  ISequenceService service = (ISequenceService)
    ctx.getBean("sequencesBean");
  try {
    id_seq = service.getUploadSequence();
  } catch (Exception e) {
   pLogger.error(e.getMessage());
  ...
}


}

10) a PortletJSFUtil class

...

import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import org.springframework.context.ApplicationContext;
import
org.springframework.web.portlet.context.PortletApplicationContextUtils;

...


private static ExternalContext getExternalContext() {
  return FacesContext.getCurrentInstance().getExternalContext();
}

public static ApplicationContext getApplicationContext() {
return
PortletApplicationContextUtils.getRequiredWebApplicationContext((PortletContext)
getExternalContext().getContext());
}

...

11) in a servlet class

...

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.company.portlets.xxx.galery.dao.ISequenceService;
...

WebApplicationContext ctx =
WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
ISequenceService service=(ISequenceService)ctx.getBean("sequencesBean");

long id_seq = -1;

try {
  id_seq = service.getUploadSequence();
} catch (Exception e) {
  pLogger.error(e.toString());
}

...




Andreas Niemeyer schrieb:
> Hi,
>
> Does someone knows a basic example for this combination?
>
> I found one tiny example which is a bit incomplete. I guess for Spring a
> DelegatingVariableResolver is required for the managed beans.
>
> http://ffzhuang.blogspot.com/2007/04/jsf-spring-ibatis-integrate.html
>
> Thank you!
>
>
> Kind regards,
> Andreas
>
>



分享到:
评论

相关推荐

    struts2+spring+ibatis+mysql

    "Struts2+Spring+Ibatis+MySQL" 是一个经典的Java Web开发框架组合,用于构建高效、可扩展的企业级应用程序。这个组合集成了强大的MVC(Model-View-Controller)框架Struts2、依赖注入与面向切面编程的Spring框架、...

    Struts2+iBATIS+Spring整合

    Struts2+iBATIS+Spring整合是Java Web开发中一种常见的技术栈组合,这三种框架协同工作,可以构建出高效、灵活的企业级应用。Struts2作为MVC(Model-View-Controller)架构的一部分,主要负责处理HTTP请求,管理前端...

    ibatis+Spring demo

    内容包里面是源代码,运行该例子的方式就是,使用里面的sql文件还原数据库。...使用cmd进入该解压包,运行 java -jar *.jar ibatis2spring....欲了解代码的详细,请访问作者博客,搜索《ibatis + Spring 多表查询》文章。

    JSF+Spring+Ibatis示例

    JSF+Spring+Ibatis示例,对学习JAVA企业应用开发有巨大的帮助!

    compass+ibatis+spring+struts2整合开发

    compass+ibatis+spring+struts2整合开发compass+ibatis+spring+struts2整合开发compass+ibatis+spring+struts2整合开发compass+ibatis+spring+struts2整合开发

    ibatis+spring+struts2 整合开发例子

    "ibatis+spring+struts2 整合开发例子"就是一个典型的Java Web应用集成开发案例,旨在帮助开发者理解和掌握这三大框架的协同工作原理。接下来,我们将详细讨论这三个组件以及它们的整合过程。 Ibatis是一个轻量级的...

    struts2+ibatis+spring 安例

    Struts2、iBatis和Spring是Java Web开发中非常重要的三个框架,它们共同构建了一个高效、灵活的应用架构。这个实例结合了这三个框架,旨在帮助开发者理解如何将它们整合在一起,提升开发效率。 Struts2作为MVC...

    Struts2-Ibatis+spring.rar

    Struts2-Ibatis+spring.rar Struts2-Ibatis+spring.rar Struts2-Ibatis+spring.rar Struts2-Ibatis+spring.rar Struts2-Ibatis+spring.rar

    Ibatis+Spring+struts1框架搭建

    【标题】:Ibatis+Spring+Struts1框架搭建 在Web开发中,Ibatis、Spring和Struts1是三个非常重要的组件,它们分别负责不同的职责。Ibatis是一个优秀的持久层框架,Spring是一个全面的后端应用框架,而Struts1则是一...

    oa_权限系统ibatis+spring+struts2

    oa_权限系统ibatis+spring+struts2 oa_权限系统ibatis+spring+struts2 oa_权限系统ibatis+spring+struts2

    ibatis+Spring+struts2整合实例

    本实例关注的是“ibatis+Spring+struts2”的整合,这是一个经典的Java Web开发组合,用于实现数据访问、业务逻辑控制和用户界面交互。下面我们将深入探讨这三个组件及其整合的关键知识点。 1. **iBATIS**:iBATIS...

    ibatis+spring+struts

    在IT行业中,集成框架是构建复杂企业级应用的常用手段,而"Ibatis+Spring+Struts"就是一个经典的Java Web开发组合,也被称作SSM框架。这个框架集合了Struts的MVC设计模式、Spring的依赖注入和事务管理以及Ibatis的...

    webwork+ibatis+spring oracle c3p0 集成框架

    【webwork+ibatis+spring oracle c3p0 集成框架】 WebWork、iBatis、Spring 和 Oracle C3P0 是四个在企业级Java应用开发中常用的组件,它们各自扮演着不同的角色,而将它们集成在一起可以构建一个高效、灵活且可...

    struts2+spring+ibatis+jquery ajax的登陆注册实时验证

    Struts2、Spring、iBatis和jQuery AJAX是Java Web开发中的四大核心技术,它们共同构建了一个功能强大的MVC(模型-视图-控制器)架构。本文将深入探讨这些技术在登录注册系统中的应用。 首先,Struts2是Apache基金会...

    backbone+bootstrap+ibatis+spring例子

    结合这四个技术,"backbone+bootstrap+ibatis+spring例子"创建了一个完整的Web应用解决方案,前端利用Backbone.js进行状态管理和界面渲染,Bootstrap提升UI体验,后端则借助Spring处理业务逻辑并与数据库交互。...

    Ibatis+Spring+struts完整代码案例

    【Ibatis+Spring+Struts整合详解】 Ibatis、Spring和Struts是Java Web开发中的三大框架,它们各自负责不同的职责,共同构建了一个强大的企业级应用框架。Ibatis作为持久层框架,处理数据库操作;Spring提供了依赖...

    maven+ibatis+spring mvc源码

    【标题】"maven+ibatis+spring mvc源码" 涉及到的是一个典型的Java Web开发架构,结合了Maven项目管理工具、MyBatis持久层框架以及Spring MVC作为控制器层的实现。这一组合是现代企业级应用开发中的常见选择,具有...

    struts2+ibatis+spring+Hessian 整合项目

    struts2+ibatis+spring+Hessian 整合项目 web项目整合,服务端用hessian协议远程调用服务端的方法,hessian是用spring代理整合,struts2+ibatis+spring的整合项目,用作学习和开发基础平台构建很有用处,工程导入...

    ibatis+spring+struts2

    "ibatis+spring+struts2"是一个常见的技术栈组合,它涵盖了数据访问、业务逻辑和用户界面三个层面。这三个框架的整合使得开发过程更加顺畅,同时也提供了良好的分层架构。以下是对这个技术组合的详细解释: 1. **...

    struts2+ibatis+spring框架整合

    struts2+ibatis+spring框架整合

Global site tag (gtag.js) - Google Analytics