ssh整合

       對Struts、springhibernate大體上了解一遍後,就是針對這個幾個框架的整合了。如何整合,請看下面:

第一:Struts2的jar和xml配置文件:

        jar包:

                 commons-fileupload-1.2.1.jar:文件上傳

                 commons-io-1.3.2.jar:文件讀取工具類

                 freemarker-2.3.15.jar:模板引擎,基於模板生成文本輸出的通用工具。

                 ognl-2.7.3.jar:功能強大的表達式語言,替代EL表達式,進行數據綁定和顯示

                 struts2-core-2.1.8.1.jar:struts2核心包

                 xwork-core-2.1.6.jar:xwork核心包,是struts2的底層核心


        xml文件有:web.xml  (配置struts2的核心過濾器) 

                            struts.xml (配置資源訪問)


第二:Spring的jar和xml配置文件

        jar包:

                spring.jar:包含有完整發布模塊的單個jar 包。但是不包括mock.jar, aspects.jar, spring-portlet.jar, and spring-hibernate2.jar

                commons-logging:針對日誌處理的

                aspectjrt:支持aop的jar

                cglib-nodep-2.1_3:配合支持aop的jar

                aspectjweaver.jsr 和 aspectjrt.jar:springAOP需要的包


       xml文件有:applicationContext.xml


第三:Hibernate的jar和xml配置文件

       jar包:

               Hibernate3.jar:Hibernate的核心庫

               antlr-2.7.6.jar:執行HQL語句的支持包

               cglib-asm.jar:CGLIB庫,hibernate用它來實現PO字節碼的動態生成

               dom4j.jar: dom4j:Java的XML API

               commons-collections.jar: Apache Commons包中的一個,包含了一些Apache開發的集合類,功能比java.util.*強大

              commons-logging.jar: Apache Commons包中的一個,包含了日誌功能

              c3p0.jar: C3PO是一個數據庫連接池,Hibernate可以配置爲使用C3PO連接池。

              jta.jar: JTA規範,當Hibernate使用JTA的時候需要

              MySQL-connector-java-5.1.5-bin.jar:鏈接mySql必須得包


       xml文件有:hibernate.cfg.xml :針對每個實體持久化所做的配置,數據庫連接用戶名密碼等等。

                          xx.hbm.xml:每個實體對應一個


第四:Spring和Struts2、Spring和Hibernate整合時的XML配置和相關jar包

jar包:
         Struts2和Spring整合時的jar:struts2-spring-plugin-2.1.8.1.jar是strus2和spring的一個整合插件。

         Spring和Hibernate整合時不需要額外的jar包



1)Web.xml配置

[html] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. <?xml version="1.0" encoding="UTF-8"?>    
  2. <web-app version="2.5"     
  3.     xmlns="http://java.sun.com/xml/ns/javaee"     
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     
  5.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee     
  6.     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">    
  7.       
  8.     <!--     配置spring的用於初始化容器對象的監聽器 -->  
  9.     <listener>  
  10.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  11.     </listener>  
  12.     <context-param>  
  13.     <param-name>contextConfigLocation</param-name>  
  14.     <param-value>  
  15.         /WEB-INF/classes/applicationContext*.xml   
  16.    </param-value>  
  17. </context-param>  
  18.   
  19.   
  20. <!-- ~~~~~~~~~~~struts2的配置  start~~~~~~~~~~~ -->  
  21.   <filter>    
  22.     <filter-name>struts2</filter-name>    
  23.     <filter-class>    
  24.         org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter    
  25.     </filter-class>    
  26.   </filter>    
  27.   <filter-mapping>    
  28.     <filter-name>struts2</filter-name>    
  29.     <url-pattern>/*</url-pattern>    
  30.   </filter-mapping>  
  31. <!-- ~~~~~~~~~~~struts2的配置  end~~~~~~~~~~~ -->    
  32.    
  33.   
  34.   <welcome-file-list>    
  35.     <welcome-file>index.jsp</welcome-file>    
  36.   </welcome-file-list>    
  37.     
  38.   </web-app>    


       2):Struts的Struts.xml配置

[html] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. <?xml version="1.0" encoding="UTF-8" ?>    
  2. <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">    
  3. <struts>    
  4.   
  5.     <!--     設置爲開發模式 -->  
  6.     <constant name="struts.devMode" value="true" />  
  7.     <!--     擴展名配置爲action -->  
  8.     <constant name="struts.action.extension" value="action"/>    
  9.      <!-- 主題,將值設置爲simple,即不使用UI模板。這將不會生成額外的html標籤 -->  
  10.     <constant name="struts.ui.theme" value="simple" />  
  11.    
  12. </struts>     

        3)Spring的applicationContext.xml配置

[html] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.      xmlns:context="http://www.springframework.org/schema/context"  
  5.     xmlns:tx="http://www.springframework.org/schema/tx"  
  6.     xsi:schemaLocation="  
  7.     http://www.springframework.org/schema/beans   
  8.     http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
  9.                 http://www.springframework.org/schema/context   
  10.                 http://www.springframework.org/schema/context/spring-context-2.5.xsd  
  11.                 http://www.springframework.org/schema/tx   
  12.                 http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">  
  13.       
  14.     <!--導入外部properties文件 -->  
  15.      <context:property-placeholder location="classpath:jdbc.properties"/>  
  16.         
  17.          
  18.     <!--  配置SessionFactory -->  
  19.     <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  20.         <!--     指定hibernate配置文件的位置 -->  
  21.         <property name="configLocation" value="classpath:hibernate.cfg.xml"></property>  
  22.         <!--     連接池 -->  
  23.         <property name="dataSource" >  
  24.             <bean class="com.mchange.v2.c3p0.ComboPooledDataSource">  
  25.                   <!--mysql數據庫驅動 -->    
  26.                 <property name="driverClass" value="${driverClass}"></property>    
  27.                 <!-- mysql數據庫名稱 -->    
  28.                 <property name="jdbcUrl" value="${jdbcUrl}"></property>    
  29.                 <!-- 數據庫的登陸用戶名 -->    
  30.                 <property name="user" value="${user}"></property>    
  31.                 <!-- 數據庫的登陸密碼 -->    
  32.                 <property name="password" value="${password}"></property>    
  33.                 <!-- 方言:爲每一種數據庫提供適配器,方便轉換 -->    
  34.                 <!-- <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>   -->  
  35.                   
  36.                 <!-- 其他配置 -->  
  37.                 <!--初始化時獲取三個連接,取值應在minPoolSize與maxPoolSize之間。Default: 3 -->  
  38.                 <property name="initialPoolSize" value="3"></property>  
  39.                 <!--連接池中保留的最小連接數。Default: 3 -->  
  40.                 <property name="minPoolSize" value="3"></property>  
  41.                 <!--連接池中保留的最大連接數。Default: 15 -->  
  42.                 <property name="maxPoolSize" value="5"></property>  
  43.                 <!--當連接池中的連接耗盡的時候c3p0一次同時獲取的連接數。Default: 3 -->  
  44.                 <property name="acquireIncrement" value="3"></property>  
  45.                 <!-- 控制數據源內加載的PreparedStatements數量。如果maxStatements與maxStatementsPerConnection均爲0,則緩存被關閉。Default: 0 -->  
  46.                 <property name="maxStatements" value="8"></property>  
  47.                 <!--maxStatementsPerConnection定義了連接池內單個連接所擁有的最大緩存statements數。Default: 0 -->  
  48.                 <property name="maxStatementsPerConnection" value="5"></property>  
  49.                 <!--最大空閒時間,1800秒內未使用則連接被丟棄。若爲0則永不丟棄。Default: 0 -->  
  50.                 <property name="maxIdleTime" value="1800"></property>  
  51.             </bean>  
  52.         </property>  
  53.     </bean>  
  54.   
  55.  </beans>    


     4)Hibernate的hibernate.cfg.xml配置和xx.hbm.xml配置

hibernate.cfg.xml

[html] view plain copy
 在CODE上查看代碼片派生到我的代碼片
  1. <!DOCTYPE hibernate-configuration PUBLIC    
  2.     "-//Hibernate/Hibernate Configuration DTD 3.0//EN"    
  3.     "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">    
  4.     
  5. <hibernate-configuration>    
  6.     <session-factory >    
  7.         <!-- 方言:爲每一種數據庫提供適配器,方便轉換 -->    
  8.         <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>    
  9.           
  10.         <property name="show_sql">true</property>  
  11.         <property name="hbm2ddl.auto">update</property>  
  12.            
  13.     </session-factory>    
  14. </hibernate-configuration>   

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章