---
title: "Struts 2+Hibernate 3+Spring 2 + tiles 2整合所需jar档"
author: "alert_mm"
date: "2009-03-27T09:28:30Z"
tags: []
categories: ["企业架构"]
slug: "struts-2-hibernate-3-spring-2-tiles-2-jar"
draft: false
lastmod: "2009-03-27T09:28:30Z"
id: 355906
url: "https://alert-mm.iteye.com/blog/355906"
---

1）Spring 2.5所需jar包：(可通过MyEclipse/Project Capabilities/Add Spring Capabilities添加这些jar档)  
 spring-beans.jar  
 spring-context.jar  
 spring-core.jar  
 commons-attributes-api.jar  
 commons-attributes-compiler.jar  
 commons-logging.jar  
 log4j-1.2.15.jar

2）以下是在struts2中必须有的与tiels2相关的文件，考贝到项目的lib目录就ＯＫ了。  
 用struts-2.1.2版本是如果只导入：commons-logging-1.0.4.jar、freemarker-2.3.12.jar、ognl-2.6.11.jar、struts2-core-2.1.2.jar、xwork-2.1.1.jar这五个包(比如struts-2.0.11及更往前的版本,很多教程都是这样的配置的),就会报struts2-core-2.1.2.jar!/struts-default异常解决办法是还得加入如下两个  
commons-io-1.3.2.jar、commons-fileupload-1.2.1.jar  
   
 struts2-tiles-plugin.jar、

 tiles-api-2.0.4.jar、tiles-core-2.0.4.jar、tiles-jsp-2.04.jar

后三个文件，从tiles.apache.org下载tiles工程。、

3）#with tiles 2.0.5  
 commons-beanutils-1.7.0.jar、commons-digester-1.8.jar、  
 tiles-core-2.0.5.jar、tiles-api-2.0.5.jar、tiles-jsp-2.0.5.jar

4）hibernate3.2核心jar包：  
 jta.jar（标准的JTA API）、commons-logging.jar（日志功能）、commons-collections.jar（集合类）、antlr.jar（ANother Tool for Language Recognition）、dom4j.jar（XML配置和映射解释器）、Hibernate3.jar（核心库）、ehcache.jar（如果没有其它的缓存，则它是必要的）

5）oracle驱动jar档：classes12.jar

综合Spring 2.5 + Hibernate 3 + Struts 2.1 + tiles 2 + oracle9i所需jar包有：  
   
 spring-beans.jar  
 spring-context.jar  
 spring-core.jar  
 commons-attributes-api.jar  
 commons-attributes-compiler.jar  
 commons-logging.jar  
 log4j-1.2.15.jar  
   
 antlr.jar  
 jta.jar  
 jstl.jar  
 commons-logging.jar  
 commons-collections.jar  
 dom4j.jar  
 Hibernate3.jar  
 ehcache.jar

 commons-logging-1.0.4.jar  
 freemarker-2.3.12.jar  
 ognl-2.6.11.jar  
 struts2-core-2.1.2.jar  
 xwork-2.1.1.jar  
 commons-io-1.3.2.jar  
 commons-fileupload-1.2.1.jar

 struts2-tiles-plugin.jar

 tiles-api-2.0.4.jar  
 tiles-core-2.0.4.jar  
 tiles-jsp-2.04.jar  
 commons-digester-1.8.jar  
 commons-beanutils-1.7.0.jar

 classes12.jar

 后加上：ehcache-1.1.jar,asm.jar,aspectjweaver-1.5.2a.jar,c3p0-0.9.0.jar,cglib-2.1.3.jar,spring-hibernate3.jar,spring.jar,struts2-spring-plugin-2.0.11.jar

6）struts2 +hibernate3+Spring 的一点总结

 1：首先必须要注意的是不能在struts2的action中直接调用继承hibernateSupport的DAO，不然好多东西无法初始化，会抛出：java.lang.NULLException．在action中只能初始话的是从页面传过来的数据。而action必须要调用业务逻辑层来完成具体的工作。

 所以应该有这么个模式:

 1：让spring管理所有的bean。hibernate的datasource sessionFactory。还有我们自己的具体dao，这里要注意我们的dao必须要引用sessionFactory，所以要把 sessionFactory注入到我们的dao中由我们自己的dao借助sessionFactory 产生的hibernateTemplate来完成具体共组。

 HibernateDaoSupport 已经为我们注入好了sessionFactory.

 接着我们要定义业务逻辑层，然后把业务逻辑bean由spring管理。因为业务逻辑需要dao，所以把我们的dao注入到业务逻辑层，我们的业务逻辑层把需要的一些东西都弄好。然后我们把struts2的action的class交给spring管理，然后在这个bean中注入action需要的逻辑bean.

7）在struts 2 中使用tiles-2.0.4时，需在web.xml中加入如下listener:  
 &lt;listener&gt;  
        &lt;listener-class&gt;org.apache.struts2.tiles.StrutsTilesListener&lt;/listener-class&gt;  
  &lt;/listener&gt;  
   同时在头部加入tiles-defs.xml文件配置：如：  
 &lt;context-param&gt;  
       &lt;param-name&gt;org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS\_CONFIG&lt;/param-name&gt;  
       &lt;param-value&gt;&lt;!-- 多个tiles文件在此以英文逗号隔开 --&gt;  
        /WEB-INF/tiles/tiles-defs.xml,/WEB-INF/tiles/tiles-about.xml  
       &lt;/param-value&gt;  
      &lt;/context-param&gt;

   注意：在tiles-defs.xml文件中的doctype声明应为：  
 &lt;!DOCTYPE tiles-definitions PUBLIC  
       "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"  
       "[http://tiles.apache.org/dtds/tiles-config\_2\_0.dtd](http://tiles.apache.org/dtds/tiles-config_2_0.dtd)"&gt;  
  而不是  
   
&lt;!DOCTYPE tiles-definitions PUBLIC  
        "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"  
        "[http://struts.apache.org/dtds/tiles-config\_2\_0.dtd](http://struts.apache.org/dtds/tiles-config_2_0.dtd)"&gt;  
  否则 定义时 put-attribute 会出现红叉。