首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

ssh环境筹建需要的jar包2

2012-06-28 
ssh环境搭建需要的jar包2hibernate-distribution-3.3.2.GA\lib\required\*.jar(必须)hibernate-distribut

ssh环境搭建需要的jar包2
hibernate-distribution-3.3.2.GA\lib\required\*.jar(必须);
hibernate-distribution-3.3.2.GA\hibernate3.jar(必须);     
hibernate-distribution-3.3.2.GA\lib\optional\ehcache\*.jar(hibernate 二级缓存);

这里也需要注意: spring 中的 antlr-2.7.2.jar 和 hibernate 中的 antlr-2.7.6.jar 冲突, 删除低版本的:  antlr-2.7.2.jar

5. 加入配置文件:
  ---------- struts 的配置文件----------
  1). 在 项目的根目录下新建 confsourceFolder, 用来存放项目的配置文件.
  2). 加入 struts 的配置文件: 复制struts-1.3.8\apps\struts-blank-1.3.8\WEB-INF 目录下的 struts-config.xml和 validation.xml 到 conf 目录下.
           并且修改 web.xml 文件, 加入许下内容 
     <servlet>
       <servlet-name>action</servlet-name>
       <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
       <init-param>
          <param-name>config</param-name>
          <param-value>/WEB-INF/classes/struts-config.xml</param-value>
       </init-param>
       <load-on-startup>2</load-on-startup>
    </servlet>
   
   
     <!-- Standard Action Servlet Mapping-->
     <servlet-mapping>
       <servlet-name>action</servlet-name>
       <url-pattern>*.do</url-pattern>
     </servlet-mapping>
  3). 修改 struts-config.xml 文件中关于validation 框架的配置如下(第四行 WEB-INF/后加入 classes):
        <plug-inclassName="org.apache.struts.validator.ValidatorPlugIn">
      <set-property
          property="pathnames"
          value="/org/apache/struts/validator/validator-rules.xml,
                 /WEB-INF/classes/validation.xml"/>
     </plug-in>
    
  4). 复制 struts-1.3.8\apps\struts-blank-1.3.8\WEB-INF\classes\MessageResources.properties到 conf 目录下.                                                            
 
  ---------- spring 的配置文件----------
  5). 复制spring-framework-2.5.6.SEC01\samples\jpetstore\war\WEB-INF\applicationContext.xml到 conf 目录下.
  6). 修改 web.xml 文件, 让 web应用启动时初始化 Spring 的 IOC 容器.
   <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>
  7). spring 整合struts,  在 struts 中加入如下配置, 该配置需要加在<message-resources parameter="MessageResources"/> 节点之前:
   <controller>
    <set-property property="processorClass"
        value="org.springframework.web.struts.DelegatingRequestProcessor"/>
   </controller>
 
  ---------- hibernate 的配置文件----------
 . 可以不加入 hibernate 的配置文件. 而由spring 来进行配置.
  9). 在 conf 目录下加入jdbc.properties 文件:
  user=root
  password=1230
  driverClass=com.mysql.jdbc.Driver
  jdbcUrl=jdbc:mysql:///ems
  10). 在 conf 目录下新建applicationContext-hibernate.xml 的 spring 配置文件,在其中配置数据源和hibernate
      (注意需要加入 context 命名空间, 用于导入 jdbc.properties 文件). 因为此时需要配置数据源, 所以需要导入c3p0 和 数据库驱动的 jar 包.
               并在该文件下加入如下内容:
     
     <context:property-placeholderlocation="classpath:jdbc.properties"/>
 
   <!--配置 C3P0 数据库连接池 -->
   <beanid="dataSource"
    value="${user}"/>
    <propertyname="password" value="${password}"/>
    <propertyname="driverClass" value="${driverClass}"/>
    <propertyname="jdbcUrl" value="${jdbcUrl}"/>
   
    <!--配置 C3P0 的基本信息  -->
    <propertyname="acquireIncrement" value="2"/>
    <propertyname="initialPoolSize" value="5"/>
    <propertyname="minPoolSize" value="5"/>
    <propertyname="maxPoolSize" value="50"/>
    <propertyname="maxStatements" value="0"/>
    <propertyname="maxStatementsPerConnection" value="5"/>
   </bean>
  
   <beanid="sessionFactory"
    ref="dataSource"/>
   
    <!--配置 hibernate 的基本属性 -->
    <propertyname="hibernateProperties">
     <props>
      <!--数据库方言 -->
      <propkey="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
      <!--是否打印 SQL 文 -->
      <propkey="hibernate.show_sql">true</prop>
      <!--是否格式化 SQL 文 -->
      <propkey="hibernate.format_sql">true</prop>
      <!--是否创建数据表 -->
      <propkey="hibernate.hbm2ddl.auto">update</prop>
     
      <!--批量抓取 -->
      <propkey="hibernate.jdbc.fetch_size">150</prop>
      <!--批量更新 -->
      <propkey="hibernate.jdbc.batch_size">30</prop>
     
      <!--启用二级缓存 -->
      <propkey="hibernate.cache.use_second_level_cache">true</prop>
      <!--配置二级缓存的产品 -->
      <propkey="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
     </props>
    </property>
   
    <!--配置 hibernate 的 hbm 文件 -->
    <propertyname="mappingResources">
     <list>
      <!---->
     </list>
    </property>
   </bean>
  
   在applicationContext.xml 文件中导入 applicationContext-transaction.xml文件
  
  11). 因为需要使用 ehcache 作为二级缓存的产品,所以需要把 hibernate-distribution-3.3.2.GA\project\etc\ehcache.xml 复制到 conf目录下
              并导入 ehcache 的 jar 包:
 
  12). 配置 spring 的声明式事务:
   a. 在 conf目录下新建 spring 配置文件: applicationContext-transaction.xml
   b. 在applicationContext.xml 文件中导入 applicationContext-transaction.xml文件:
     <importresource="classpath:applicationContext-transaction.xml"/>
   c. 在applicationContext-transaction.xml 添加如下内容:
   
    ①:配置 hibernate 的事务管理器
    <beanid="transactionManager"
     />
      <tx:methodname="get*" read-only="true"/>
     </tx:attributes>
    </tx:advice>
   
    ③:配置对哪些类的那些方法使用声明式事务
    <aop:config>
     <aop:pointcutexpression="execution(* cn.itcast.ems.service.*.*(..))"id="emsTxPointcut"/>
     <aop:advisoradvice-ref="emsTxAspect"pointcut-ref="emsTxPointcut"/>
    </aop:config>
 
  13). 创建 spring 的 Bean配置文件
   a. 在 conf目录下新建 spring 配置文件: applicationContext-beans.xml 
   b.在该文件中配置当前应用的 Bean 组件
   c. 在applicationContext.xml 文件中导入 applicationContext-beans.xml文件
  
  14). web.xml文件中还需要加入如下配置:
   ①加入 spring的字符编码过滤器:
   <filter>
    <filter-name>springCharacterEncoding</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
     <param-name>encoding</param-name>
     <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
     <param-name>forceEncoding</param-name>
     <param-value>true</param-value>
    </init-param>
   </filter>
  
   <filter-mapping>
    <filter-name>springCharacterEncoding</filter-name>
    <url-pattern>/*</url-pattern>
   </filter-mapping>

   ②加入 Spring 的OpenSessionInView 过滤器
   <filter>
    <filter-name>springOpenSessionInView</filter-name>
    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
   </filter>
  
   <filter-mapping>
    <filter-name>springOpenSessionInView</filter-name>
    <url-pattern>/*</url-pattern>
   </filter-mapping>

热点排行