support

来源:百度文库 编辑:神马文学网 时间:2024/04/28 22:38:15

一、struts2.0与spring2.0的整合

1、新建web项目

加入struts2.0和spring的各种架包。

struts2.0的基本架包:

   common-logging-1.0.4.jar      freemarker-2.3.8.jar

  ognl-2.6.11.jar      struts2-core-2.0.11.2.jar    xwork-2.0.5.jar

spring 的架包:spring-2.0.jar

特别的注意加入:

  commons-pool-1.4.jar   解决springhibernate整合时,数据源datasource的问题,可以去http://commons.apache.org/downloads/download_pool.cgi下载

  struts2-spring-plugin-2.0.11.2.jar   解决struts2spring整合时,将struts管理托管给spring

2、修改web.xml文件,加入:


  struts-cleanup
  
   org.apache.struts2.dispatcher.ActionContextCleanUp
  

 

上面一段是让程序知道在正确的时候清除请求(servletContext),而不是立即清除,方便在程序中取得servletContext。


  
   org.springframework.web.context.ContextLoaderListener
  

 

上面一段是配置spring 的监听,方便spring与web的容器交互。


  contextConfigLocation
  /WEB-INF/applicationContext.xml
 

上面是定义spring.xml文件的上下文配置,如果拥有多个spring配置文件,可以用空格或逗号隔开。

3、修改struts.xml文件

在其中加入:

struts.objectFactory"   valus="spring"/>

struts的工厂交由spring管理,由spring来创建对象,但是如果已经加入了struts2-spring-plugin-2.0.11.2.jar 的包,就可以不用加了。

 

二、springhibernate整合

1、新建一web项目,或是在struts+spring的基础上开发

2、添加spring的支持

选择需要的库文件。aop、core、persistence core、presistence JDBC、web,选择这五个库文件。

3、添加hibernate的支持

在选择hibernate配置文件时,我们选择spring configuration file ,表示下网将hibernate托管给spring进行管理,使用已经存在的spring配置文件,检查spring配置文件的位置,添加sessionFactory的BeanID,在下面给出的datasource数据源的BeanID,选择数据库的驱动名字,不创建sessionfactory class。

4、添加hibernate的反向工程

在myeclipse database explorer视图中,将表反转到hibernate中。