ssh配置

 

 S2SH(Struts2 + Spring + Hibernate)整合之配置文件

 

 

 1、Hibernate 3.2(7个):
hibernate3.jar 核心库,必须
jta.jar 必须
commons-logging.jar 必须
commons-collections.jar 必须
antlr.jar 必须
dom4j.jar 读写xml 必须
cglib-2.1.3.jar 必须
一下两个是cglib的依赖库 也是必须的
asm-attrs.jar


2、spring2.0 核心jar(5个)
spring.jar
aspectj/aspectjrt.jar、aspectjweaver.jar
jakarta-commons/commons-logging.jar
log4j/log4j-1.2.14.jar

3、struts2必须JAR包(6个):
struts2-spring-plugin-2.0.11.2.jar
xwork-2.0.5.jar
struts2-core-2.0.11.2.jar
freemarker-2.3.8.jar
ognl-2.6.11.jar

4、spring2.5必须JAR包(5个):
spring.jar
asm-2.2.2.jar
asm-commons-2.2.2.jar
asm-util-2.2.2.jar
cglib-nodep-2.1_3.jar

 

 

1.web.xml文件配置如下:

 

Web.xml代码 复制代码
  1. <?xml version="1.0" encoding="UTF-8"?>   
  2. <web-app version="2.4"    
  3.     xmlns="http://java.sun.com/xml/ns/j2ee"    
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
  5.     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee    
  6.     http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">   
  7.   
  8.  <!-- 指定spring的配置文件,默认从web根目录寻找配置文件,我们可以通过spring提供的classpath:前缀指定从类路径下寻找 -->   
  9.     <context-param>   
  10.        <param-name>contextConfigLocation</param-name>   
  11.        <param-value>classpath:beans.xml</param-value>   
  12.     </context-param>   
  13.     
  14.     <!-- 对Spring容器进行实例化,并把实例存放在application的属性里 -->   
  15.     <listener>   
  16.           <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>   
  17.     </listener>   
  18.   
  19.     <!-- 配置字符编码过滤器(解决乱码问题) -->    
  20.     <filter>   
  21.     <filter-name>encoding</filter-name>   
  22.     <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>   
  23.     <init-param>   
  24.         <param-name>encoding</param-name>   
  25.         <param-value>UTF-8</param-value>   
  26.     </init-param>   
  27.     </filter>   
  28.     <filter-mapping>   
  29.         <filter-name>encoding</filter-name>   
  30.         <url-pattern>/*</url-pattern>   
  31.     </filter-mapping>    
  32.        
  33.     <!-- 解决因session关闭而导致的延迟加载例外的问题 -->   
  34.     <filter>   
  35.             <filter-name>OpenSessionInViewFilter</filter-name>   
  36.             <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>   
  37.     </filter>   
  38.     <filter-mapping>   
  39.             <filter-name>OpenSessionInViewFilter</filter-name>   
  40.             <url-pattern>/*</url-pattern>   
  41.     </filter-mapping>   
  42.   
  43.     <!-- 配置Struts2的过滤器-->   
  44.     <filter>   
  45.            <filter-name>struts2</filter-name>   
  46.              <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>   
  47.      </filter>   
  48.    <filter-mapping>   
  49.           <filter-name>struts2</filter-name>   
  50.              <url-pattern>/*</url-pattern>   
  51.     </filter-mapping>     
  52.      
  53.   <welcome-file-list>   
  54.     <welcome-file>index.jsp</welcome-file>   
  55.   </welcome-file-list>   
  56. </web-app>  

 

2.struts.xml配置如下: 

 

Struts.xml代码 复制代码
  1. <?xml version="1.0" encoding="UTF-8" ?>   
  2. <!DOCTYPE struts PUBLIC   
  3.     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"  
  4.     "http://struts.apache.org/dtds/struts-2.0.dtd">   
  5. <struts>   
  6.    <!-- 该属性指定需要Struts 2处理的请求后缀,该属性的默认值是action,即所有匹配*.action的请求都由Struts2处理。   
  7.     如果用户需要指定多个请求后缀,则多个后缀之间以英文逗号(,)隔开。 -->   
  8.     <constant name="struts.action.extension" value="do"/>   
  9.     <!-- 设置浏览器是否缓存静态内容,默认值为true(生产环境下使用),开发阶段最好关闭 -->   
  10.     <constant name="struts.serve.static.browserCache" value="false"/>   
  11.     <!-- 当struts的配置文件修改后,系统是否自动重新加载该文件,默认值为false(生产环境下使用),开发阶段最好打开 -->   
  12.     <constant name="struts.configuration.xml.reload" value="true"/>   
  13.     <!-- 开发模式下使用,这样可以打印出更详细的错误信息 -->   
  14.     <constant name="struts.devMode" value="true" />   
  15.      <!-- 默认的视图主题 -->   
  16.     <constant name="struts.ui.theme" value="simple" />   
  17.     <constant name="struts.objectFactory" value="spring"/>   
  18.   
  19.     <package name="xwuxin" namespace="/person" extends="struts-default">   
  20.         <global-results>   
  21.             <result name="message">/WEB-INF/page/message.jsp</result>   
  22.         </global-results>   
  23.         <action name="list" class="personListAction">   
  24.             <result name="list">/WEB-INF/page/persons.jsp</result>   
  25.         </action>   
  26.         <action name="manage_*" class="personManageAction" method="{1}">   
  27.             <result name="add">/WEB-INF/page/addperson.jsp</result>   
  28.         </action>   
  29.     </package>   
  30. </struts>  

 

 

3.beans.xml配置如下:

 

Beans.xml代码 复制代码
  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:aop="http://www.springframework.org/schema/aop"  
  6.        xmlns:tx="http://www.springframework.org/schema/tx"  
  7.        xsi:schemaLocation="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/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd   
  12.            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">   
  13.        
  14.     <context:annotation-config/>    
  15.     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">   
  16.         <property name="driverClassName" value="org.gjt.mm.mysql.Driver"/>   
  17.         <property name="url" value="jdbc:mysql://localhost:3306/ss2h?useUnicode=true&amp;characterEncoding=UTF-8"/>   
  18.         <property name="username" value="root"/>   
  19.         <property name="password" value="chx/1988" />   
  20.          <!-- 连接池启动时的初始值 -->   
  21.          <property name="initialSize" value="1"/>   
  22.          <!-- 连接池的最大值 -->   
  23.          <property name="maxActive" value="500"/>   
  24.          <!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接释放一部分,一直减少到maxIdle为止 -->   
  25.          <property name="maxIdle" value="2"/>   
  26.          <!--  最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请一些连接,以避免洪峰来时再申请而造成的性能开销 -->   
  27.          <property name="minIdle" value="1"/>   
  28.     </bean>   
  29.        
  30.     <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">   
  31.          <property name="dataSource" ref="dataSource"/>   
  32.          <property name="mappingResources">   
  33.             <list>   
  34.               <value>cn/itcast/bean/Person.hbm.xml</value>   
  35.             </list>   
  36.          </property>   
  37.          <property name="hibernateProperties">   
  38.             <value>   
  39.                 hibernate.dialect=org.hibernate.dialect.MySQL5Dialect   
  40.                 hibernate.hbm2ddl.auto=update   
  41.                 hibernate.show_sql=false   
  42.                 hibernate.format_sql=false   
  43.                 hibernate.cache.use_second_level_cache=true   
  44.                 hibernate.cache.use_query_cache=false   
  45.                 hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider   
  46.               </value>   
  47.         </property>   
  48.     </bean>   
  49.   
  50.     <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">   
  51.         <property name="sessionFactory" ref="sessionFactory"/>   
  52.     </bean>   
  53.        
  54.     <aop:config>   
  55.         <aop:pointcut id="tran" expression="execution(* cn.itcast.service..*.*(..))"/>   
  56.         <aop:advisor advice-ref="txAdvice" pointcut-ref="tran"/>   
  57.     </aop:config>   
  58.     <tx:advice id="txAdvice" transaction-manager="txManager">   
  59.           <tx:attributes>   
  60.             <tx:method name="get*" read-only="true" propagation="NOT_SUPPORTED"/>   
  61.             <tx:method name="*"/>   
  62.           </tx:attributes>   
  63.     </tx:advice>   
  64.        
  65.     <bean id="personService" class="cn.itcast.service.impl.PersonServiceBean"/>   
  66.     <bean id="personListAction" class="cn.itcast.action.PersonListAction" scope="prototype"/>   
  67.     <bean id="personManageAction" class="cn.itcast.action.PersonManageAction" scope="prototype"/>   
  68.        
  69. </beans>  

 

4.ehcache.xml配置如下:

 

Ehcache.xml代码 复制代码
  1. <?xml version="1.0" encoding="UTF-8"?>   
  2. <!--    
  3.     defaultCache节点为缺省的缓存策略   
  4.      maxElementsInMemory 内存中最大允许存在的对象数量   
  5.      eternal 设置缓存中的对象是否永远不过期   
  6.      overflowToDisk 把溢出的对象存放到硬盘上   
  7.      timeToIdleSeconds 指定缓存对象空闲多长时间就过期,过期的对象会被清除掉   
  8.      timeToLiveSeconds 指定缓存对象总的存活时间   
  9.      diskPersistent 当jvm结束是是否持久化对象   
  10.      diskExpiryThreadIntervalSeconds 指定专门用于清除过期对象的监听线程的轮询时间   
  11.  -->   
  12. <ehcache>   
  13.     <diskStore path="D:/cache"/>   
  14.     <defaultCache maxElementsInMemory="1000" eternal="false" overflowToDisk="true"  
  15.         timeToIdleSeconds="120"  
  16.         timeToLiveSeconds="180"  
  17.         diskPersistent="false"  
  18.         diskExpiryThreadIntervalSeconds="60"/>   
  19.            
  20.     <cache name="cn.itcast.bean.Person" maxElementsInMemory="100" eternal="false"  
  21.     overflowToDisk="true" timeToIdleSeconds="300" timeToLiveSeconds="600" diskPersistent="false"/>   
  22. </ehcache>  

 

 

5.Person.hbm.xml配置文件如下:

 

Person.hbm.xml代码 复制代码
  1. <?xml version="1.0" encoding="UTF-8"?>   
  2. <!DOCTYPE hibernate-mapping PUBLIC   
  3.         "-//Hibernate/Hibernate Mapping DTD 3.0//EN"  
  4.         "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">   
  5. <hibernate-mapping package="cn.itcast.bean">   
  6.     <class name="Person" table="person">   
  7.         <cache usage="read-write" region="cn.xwuxin.bean.Person"/>   
  8.         <id name="id">   
  9.             <generator class="native"/>   
  10.         </id>   
  11.         <property name="name" length="10" not-null="true"/>   
  12.     </class>   
  13. </hibernate-mapping>  

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值