<!--xml进入路径web.xml/application-context.xml-->
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"
default-lazy-init="true">
<!-- 加载数据库属性文件,以便动态获取 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/config/jdbc.properties</value>
</list>
</property>
</bean>
<!-- 加载其它属性文件 -->
<bean id="properties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<!-- 其中包话数据库连接,hbm文件和连接池信息 -->
<value>/WEB-INF/config/jdbc.properties</value>
<!-- 暂时未知 -->
<value>/WEB-INF/config/jeecms/jeecms.properties</value>
<!-- 暂时未知 -->
<value>/WEB-INF/config/plug/**/*.properties</value>
</list>
</property>
<qualifier value="main"/>
</bean>
<!-- 通过PropertyUtils包操作properties属性文件中的属性,以便动态获取 -->
<bean id="propertyUtils" class="com.jeecms.common.util.PropertyUtils">
<property name="properties" ref="properties"/>
</bean>
<!-- 根据已加载的数据库属性文件,连接数据库 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<!--连接关闭时默认将所有未提交的操作回滚。Default: false -->
<property name="autoCommitOnClose" value="true"/>
<!--当连接池用完时客户端调用getConnection()后等待获取新连接的时间,
超时后将抛出 SQLException,如设为0则无限期等待。单位毫秒。Default: 0 -->
<property name="checkoutTimeout" value="${cpool.checkoutTimeout}"/>
<!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
<property name="initialPoolSize" value="${cpool.minPoolSize}"/>
<!--连接池中保留的最小连接数。-->
<property name="minPoolSize" value="${cpool.minPoolSize}"/>
<!--连接池中保留的最大连接数。Default: 15 -->
<property name="maxPoolSize" value="${cpool.maxPoolSize}"/>
<!--最大空闲时间,maxIdleTime秒内未使用则连 接被丢弃。若为0则永不丢弃。Default: 0 -->
<property name="maxIdleTime" value="${cpool.maxIdleTime}"/>
<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
<property name="acquireIncrement" value="${cpool.acquireIncrement}"/>
<!--
default : 0 单位 s
这个配置主要是为了减轻连接池的负载,比如连接池中连接数因为某次数据访问高峰导致创建了很多数据连接
但是后面的时间段需要的数据库连接数很少,则此时连接池完全没有必要维护那么多的连接,所以有必要将
断开丢弃掉一些连接来减轻负载,必须小于maxIdleTime。配置不为0,则会将连接池中的连接数量保持到minPoolSize。
为0则不处理。
-->
<property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}"/>
</bean>
<!-- 设置数据库session工厂 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!-- 动态地通过properties文件加载映射的hbm文件 -->
<property name="mappingLocations" value="#{propertyUtils.getList('hibernate.hbm')}"/>
<!-- 配置hibernate属性 -->
<property name="hibernateProperties">
<value>
<!-- 指定数据库方言 -->
hibernate.dialect=${hibernate.dialect}
<!-- 输出所有SQL语句到控制台 -->
hibernate.show_sql=false
<!-- 格式化输出sql语句 -->
hibernate.format_sql=false
<!--
这个配置意思是当你在Hibernate里面输入true的时候,Hibernate会转化为0插入数据库,
当你在Hibernate里面输入false的时候,Hibernate会转化为1插入数据库,
-->
hibernate.query.substitutions=true 1, false 0
<!-- 指定每次提交SQL的数量。参数值越大,读数据库的次数越少,速度越快。 -->
hibernate.jdbc.batch_size=20
<!--
允许查询缓存,对经常使用的List查询方式,只有在使用查询缓存时,
才会从缓存中通过id去get缓存的值;查询缓存一般缓存查询语句和查询结果的id -->
hibernate.cache.use_query_cache=true
</value>
</property>
<property name="entityInterceptor">
<ref local="treeInterceptor"/>
</property>
<property name="cacheProvider">
<ref local="cacheProvider"/>
</property>
<property name="lobHandler">
<ref bean="lobHandler" />
</property>
</bean>
<!-- 处理 LOB 数据,CLOB 类型,BLOB 类型 -->
<bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" lazy-init="true"/>
<!-- 缓存 -->
<bean id="cacheProvider" class="com.jeecms.common.hibernate3.SpringEhCacheProvider">
<property name="configLocation">
<value>/WEB-INF/config/ehcache-hibernate.xml</value>
</property>
<property name="diskStoreLocation">
<value>/WEB-INF/cache/hibernate</value>
</property>
</bean>
<!-- 栏目等树形结构 -->
<bean id="treeInterceptor" class="com.jeecms.common.hibernate3.TreeIntercptor"/>
<!-- 定义事务管理器(声明式的事务) -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 是隐式地向 Spring 容器注入 -->
<context:annotation-config/>
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
jeeCmsV7-src 源码解析之二(application-context.xml)
最新推荐文章于 2021-08-10 22:27:00 发布