<?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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--启用自动扫描 -->
<!-- <context:component-scan base-package="com.crc"> -->
<!-- <context:exclude-filter type="regex" expression=".(dao|service.impl)" /> -->
<!-- </context:component-scan> -->
<!-- <aop:aspectj-autoproxy /> -->
<context:component-scan base-package="com.crc.dao.impl" />
<context:component-scan base-package="com.crc.service.impl" />
<!-- 加载db.properties文件中的内容 -->
<context:property-placeholder location="classpath:config/db.properties" />
<bean id="placeholderConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:config/db.properties</value>
</property>
</bean>
<!-- 配置C3P0数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${datasource.driverClassName}" />
<property name="jdbcUrl" value="${datasource.url}" />
<property name="user" value="${datasource.username}" />
<property name="password" value="${datasource.password}" />
<property name="minPoolSize" value="${c3p0.minPoolSize}" />
<!-- 连接池中拥有的最大连接数 -->
<property name="maxPoolSize" value="${c3p0.maxPoolSize}" />
<!-- 连接的最大空闲时间,如果超过这个时间,某个数据库连接还没有被使用,则会断开掉这个连接如果为0,则永远不会断开连接 -->
<property name="maxIdleTime" value="${c3p0.maxIdleTime}" />
<!-- 连接池初始化时创建的连接数 -->
<property name="initialPoolSize" value="${c3p0.initialPoolSize}" />
<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
<property name="acquireIncrement" value="${c3p0.acquireIncrement}" />
<!--每60秒检查所有连接池中的空闲连接。Default: 0 -->
<property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}" />
<!-- 连接池用完时,等待获取新连接的时间 (毫秒) -->
<property name="checkoutTimeout" value="${c3p0.checkoutTimeout}" />
<property name="maxStatements">
<!-- J连接池为数据源缓存的PreparedStatement的总数。由于PreparedStatement属于单个Connection,所以
这个数量应该根据应用中平均连接数乘以每个连接的平均PreparedStatement来计算。为0的时候不缓存,
同时maxStatementsPerConnection的配置无效。 -->
<value>${c3p0.maxStatements}</value>
</property>
<property name="numHelperThreads">
<!-- C3P0是异步操作的,缓慢的JDBC操作通过帮助进程完成。扩展这些操作可以有效的提升性能, 通过多线程实现多个操作同时被执行。Default:
3 -->
<value>${c3p0.numHelperThreads}</value>
</property>
</bean>
<!-- 配置SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<!-- 向SessionFactory中注入数据源 -->
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<!-- 定义Hibernate的方言 -->
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<!-- 是否根据需要每次自动更新数据库 <prop key="hibernate.hbm2ddl.auto">update</prop> -->
<!-- 控制台显示SQL -->
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<!-- 输出格式化后的sql,方便查看 -->
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<!-- 如果开启, Hibernate将在SQL中生成有助于调试的注释信息 -->
<prop key="hibernate.use_sql_comments">true</prop>
<!-- 指定JDBC抓取数量的大小 -->
<prop key="hibernate.jdbc.fetch_size">${hibernate.jdbc.fetch_size}</prop>
<!-- 允许Hibernate使用JDBC2的批量更新. 取值 建议取5到30之间的值 -->
<prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>
<!-- 指定Hibernate在何时释放JDBC连接 -->
<prop key="hibernate.connection.release_mode">${hibernate.connection.release_mode}</prop>
<prop key="hibernate.dynamic-update">${hibernate.dynamic-update}</prop>
<!-- 处理oracle大字段 -->
<prop key="hibernate.connection.SetBigStringTryClob">true</prop>
</props>
</property>
<!-- 浏览entitys包下的所有使用Hibernate注解的JavaBean -->
<property name="packagesToScan">
<list>
<value>com.crc.bean</value>
</list>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 定义个通知,指定事务管理器 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="delete*" propagation="REQUIRED" read-only="false"
rollback-for="java.lang.Exception" />
<tx:method name="save*" propagation="REQUIRED" read-only="false"
rollback-for="java.lang.Exception" />
<tx:method name="update*" propagation="REQUIRED" read-only="false"
rollback-for="java.lang.Exception" />
<tx:method name="load*" propagation="SUPPORTS" read-only="true" />
<tx:method name="find*" propagation="SUPPORTS" read-only="true" />
<tx:method name="select*" propagation="SUPPORTS" read-only="true" />
<tx:method name="get*" propagation="SUPPORTS" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="aopMananger" expression="execution(* com.crc.service.impl.*Impl.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="aopMananger" />
<!-- <aop:aspect id="logAspect" ref="userLogger"> -->
<!-- <aop:before method="testLogger" pointcut-ref="userPointCut"></aop:before> -->
<!-- </aop:aspect> -->
</aop:config>
</beans>
applicationContext.xml
最新推荐文章于 2024-06-29 11:37:30 发布