<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-
2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-
context-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!– 配置自动扫描包 –>
<context:component-scan base-package="file"></context:component
-scan>
<!– 装载properties文件 –>
<context:property-placeholder
location="classpath:file/dbinfo.properties"/>
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-
method="close">
<property name="driverClass" value="${driverClass}"/>
<property name="jdbcUrl" value="${jdbcUrl}"/>
<property name="user" value="${user}"/>
<property name="password" value="${password}"/>
<property name="initialPoolSize"
value="${initialPoolSize}"/>
<property name="minPoolSize" value="${minPoolSize}"/>
<property name="maxPoolSize" value="${maxPoolSize}"/>
<property name="maxIdleTime" value="${maxIdleTime}"/>
<property name="acquireIncrement"
value="${acquireIncrement}"/>
<property name="idleConnectionTestPeriod"
value="${idleConnectionTestPeriod}"/>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!– 将bean的hibernate配置文件整合到 spring中
<property name="mappingLocations">
<list>
<value>classpath:file/\*/\*.hbm.xml</value>
</list>
</property>
–>
<!– 依然将配置文件放到主hibernate中 –>
<property name="configLocation"
value="classpath:hibernate.cfg.xml"/>
<property name="hibernateProperties">
<value>
<!– 数据库方言
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
–>
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
<!– 根据映射文件,生成表结构的方式 –>
<!– hibernate.hbm2ddl.auto=update –>
<!– 在执行时是否现实sql语句 开发阶段开启,
使用阶段移除–>
<!– hibernate.show_sql=true –>
<!– hibernate.format_sql=false –>
<!– 使用缓存,默认是开启的,这句可以不写
–>
hibernate.cache.use_second_level_cache=true
<!– 缓存用到的类 –>
hibernate.cache.provider_class=org.hibernate.cache.OSCacheProvider
<!– 开启缓存统计,开发阶段建议打开 –>
<!–
hibernate.generate_statistics=true –>
</value>
</property>
</bean>
<!– 将共用的配置文件装载到spring主配置文件中 –>
<import resource="file/spring-common.xml"/>
<!– 事物管理 –>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory"
ref="sessionFactory"></property>
</bean>
<tx:advice id="txAdvice" transaction-
manager="transactionManager">
<tx:attributes>
<tx:method name="add\*" propagation="REQUIRED"
/>
<tx:method name="save\*" propagation="REQUIRED"
/>
<tx:method name="merge\*" propagation="REQUIRED"
/>
<tx:method name="del\*" propagation="REQUIRED"
/>
<tx:method name="update\*"
propagation="REQUIRED" />
<tx:method name="\*" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut expression="execution(\*
com.sky.skyesr.impl.\*Impl.\*(..))"
id="allMethods" />
<aop:advisor advice-ref="txAdvice" pointcut-
ref="allMethods" />
</aop:config>
</beans>