ssh整合

来源:互联网 发布:java io流写入文件 编辑:程序博客网 时间:2024/06/05 22:40

       对Struts、spring、hibernate大体上了解一遍后,就是针对这个几个框架的整合了。如何整合,请看下面:

第一: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>   

0 0