applicationContext.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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" 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/tx http://www.springframework.org/schema/tx/spring-tx-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/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-lazy-init="false">
<context:component-scan base-package="com.group.users"></context:component-scan>

<bean id="sysDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver">
</property>
<property name="user" value="root"></property>
<property name="password" value=""></property>
<property name="jdbcUrl"
value="jdbc:mysql://127.0.0.1:3306/cwgl?useUnicode=true&amp;characterEncoding=utf-8">
</property>
<!-- 连接池中的最大连接数 -->
<property name="maxPoolSize" value="150" />
<!-- 连接池中的最小连接数 -->
<property name="minPoolSize" value="1"></property>
<!-- 初始化连接池中的 连接数,取值 在 minPoolSize 和 maxPoolSize 之间,default:3-->
<property name="initialPoolSize" value="3" />
<!-- 最大空闲时间,60s内该连接没有被使用则被丢弃,若为0 永不丢弃.default:0 -->
<property name="maxIdleTime" value="60" />
<!-- 当连接数不够时,每次同时创建多少个连接 -->
<property name="acquireIncrement" value="1" />
<!-- 每60s检查连接池中的所有空间连接,如果没有被使用,就被放弃, default:0 -->
<property name="idleConnectionTestPeriod" value="60" />
</bean>
<!--从c3p0数据源中抽取出JDBC的代理对象-->
<bean id="nativeJdbcExtractor"
class="org.springframework.jdbc.support.nativejdbc.C3P0NativeJdbcExtractor"
lazy-init="true" />


<!-- 将Hibernate中的事物交给Spring进行接管 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<!-- 指定sessiongFactory中的数据源 -->
<property name="dataSource" ref="sysDataSource" />

<!-- 指定hibernate的属性 -->
<property name="hibernateProperties">
<value>
<!-- hibernate使用的 方言 -->
hibernate.dialect=org.hibernate.dialect.MySQLDialect
<!-- 格式化sql -->
hibernate.format_sql=false
<!-- 是否打印出sql语句 -->
hibernate.show_sql=true
</value>
</property>
<!-- 指定hibernate的映射文件 -->
<property name="annotatedClasses">
<list>
<value>com.group.users.entity.Users</value>
</list>
</property>
</bean>
</beans>

posted @ 2016-05-31 15:19  方少520  阅读(101)  评论(0编辑  收藏  举报