jeecms 2012 源码分析(8) 相关配置文件分析

本文详细介绍了Spring框架结合C3P0数据库连接池及Hibernate ORM技术的配置方法,包括Spring核心配置文件application-context.xml的具体设置,C3P0连接池参数解释及Hibernate相关属性配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

application-context.xml

 转载请标识出处 by chenbo:http://blog.youkuaiyun.com/chenbo19867758/article/details/12844765

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.     xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"  
  4.     xmlns:context="http://www.springframework.org/schema/context"  
  5.     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
  6.     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd  
  7.     http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd  
  8.     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"  
  9.     default-lazy-init="true">  
  10.   
  11.     <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
  12.         <property name="locations">  
  13.             <list>  
  14.                 <value>/WEB-INF/config/jdbc.properties</value>  
  15.             </list>  
  16.         </property>  
  17.     </bean>  
  18.     <!-- C3P0 数据库连接池配置 -->  
  19.     <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">  
  20.         <property name="driverClass" value="${jdbc.driverClassName}" />  
  21.         <property name="jdbcUrl" value="${jdbc.url}" />  
  22.         <property name="user" value="${jdbc.username}" />  
  23.         <property name="password" value="${jdbc.password}" />  
  24.         <!--连接关闭时默认将所有未提交的操作回滚。Default: false -->   
  25.         <property name="autoCommitOnClose" value="true"/>  
  26.         <!--当连接池用完时客户端调用getConnection()后等待获取新连接的时间,  
  27.             超时后将抛出 SQLException,如设为0则无限期等待。单位毫秒。Default: 0 -->   
  28.         <property name="checkoutTimeout" value="${cpool.checkoutTimeout}"/>  
  29.         <!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->   
  30.         <property name="initialPoolSize" value="${cpool.minPoolSize}"/>  
  31.         <!--连接池中保留的最小连接数。-->   
  32.         <property name="minPoolSize" value="${cpool.minPoolSize}"/>  
  33.         <!--连接池中保留的最大连接数。Default: 15 -->   
  34.         <property name="maxPoolSize" value="${cpool.maxPoolSize}"/>  
  35.         <!--最大空闲时间,maxIdleTime秒内未使用则连 接被丢弃。若为0则永不丢弃。Default: 0 -->   
  36.         <property name="maxIdleTime" value="${cpool.maxIdleTime}"/>  
  37.         <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->   
  38.         <property name="acquireIncrement" value="${cpool.acquireIncrement}"/>  
  39.         <!--  
  40.             default : 0 单位 s  
  41.             这个配置主要是为了减轻连接池的负载,比如连接池中连接数因为某次数据访问高峰导致创建了很多数据连接  
  42.             但是后面的时间段需要的数据库连接数很少,则此时连接池完全没有必要维护那么多的连接,所以有必要将  
  43.             断开丢弃掉一些连接来减轻负载,必须小于maxIdleTime。配置不为0,则会将连接池中的连接数量保持到minPoolSize。  
  44.             为0则不处理。   
  45.          -->  
  46.         <property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}"/>  
  47.     </bean>  
  48.     <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  49.         <property name="dataSource" ref="dataSource"/>      
  50.         <property name="mappingLocations">  
  51.             <list>  
  52.                 <value>classpath*:/com/jeecms/core/entity/hbm/*.hbm.xml</value>  
  53.                 <value>classpath*:/com/jeecms/cms/entity/main/hbm/*.hbm.xml</value>  
  54.                 <value>classpath*:/com/jeecms/cms/entity/assist/hbm/*.hbm.xml</value>  
  55.             </list>  
  56.         </property>  
  57.         <property name="hibernateProperties">  
  58.             <value>  
  59.             <!-- 指定数据库方言 -->  
  60.             hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect  
  61.             <!-- 输出所有SQL语句到控制台 -->  
  62.             hibernate.show_sql=false  
  63.             <!-- 格式化输出sql语句 -->  
  64.             hibernate.format_sql=false  
  65.             <!--   
  66.                 这个配置意思是当你在Hibernate里面输入true的时候,Hibernate会转化为0插入数据库,  
  67.                 当你在Hibernate里面输入false的时候,Hibernate会转化为1插入数据库,  
  68.              -->  
  69.             hibernate.query.substitutions=true 1, false 0  
  70.             <!-- 指定每次提交SQL的数量。参数值越大,读数据库的次数越少,速度越快。 -->  
  71.             hibernate.jdbc.batch_size=20  
  72.             <!--   
  73.                 允许查询缓存,对经常使用的List查询方式,只有在使用查询缓存时,  
  74.                 才会从缓存中通过id去get缓存的值;查询缓存一般缓存查询语句和查询结果的id -->  
  75.             hibernate.cache.use_query_cache=true  
  76.             </value>  
  77.         </property>  
  78.         <property name="entityInterceptor">     
  79.             <ref local="treeInterceptor"/>  
  80.         </property>  
  81.         <property name="cacheProvider">  
  82.             <ref local="cacheProvider"/>  
  83.         </property>  
  84.         <property name="lobHandler">  
  85.             <ref bean="lobHandler" />  
  86.         </property>  
  87.     </bean>  
  88.     <!-- 处理 LOB 数据,CLOB 类型,BLOB 类型 -->  
  89.     <bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" lazy-init="true"/>  
  90.   
  91.     <!-- 缓存 -->  
  92.     <bean id="cacheProvider" class="com.jeecms.common.hibernate3.SpringEhCacheProvider">  
  93.         <property name="configLocation">  
  94.             <value>classpath:ehcache-hibernate.xml</value>  
  95.         </property>  
  96.         <property name="diskStoreLocation">  
  97.             <value>/WEB-INF/cache/hibernate</value>  
  98.         </property>  
  99.     </bean>  
  100.     <!-- 栏目等树形结构 -->  
  101.     <bean id="treeInterceptor" class="com.jeecms.common.hibernate3.TreeIntercptor"/>  
  102.     <!-- 定义事务管理器(声明式的事务) -->    
  103.     <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  104.         <property name="sessionFactory" ref="sessionFactory" />  
  105.     </bean>  
  106.     <!-- 是隐式地向 Spring 容器注册 -->  
  107.     <context:annotation-config/>  
  108.     <tx:annotation-driven transaction-manager="transactionManager" />  
  109. </beans> 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值