`

Spring C3P0 配置文件

    博客分类:
  • Java
阅读更多
<?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:context="http://www.springframework.org/schema/context"
        xmlns:jee="http://www.springframework.org/schema/jee" 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/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
   
    <!-- 定义数据源Bean,使用C3P0数据源实现-->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <!-- 指定连接数据库的驱动-->
        <property name="driverClass" value="com.mysql.jdbc.Driver"/>
        <!-- 指定连接数据库的URL-->
        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/spring_hibernate"/>
        <!-- 指定连接数据库的用户名-->
        <property name="user" value="root"/>
        <!-- 指定连接数据库的密码-->
        <property name="password" value="root"/>
        <!-- 指定连接池中保留的最大连接数. Default:15-->
        <property name="maxPoolSize" value="15"/>
        <!-- 指定连接池中保留的最小连接数-->
        <property name="minPoolSize" value="10"/>
        <!-- 指定连接池的初始化连接数  取值应在minPoolSize 与 maxPoolSize 之间.Default:3-->
        <property name="initialPoolSize" value="5"/>
        <!-- 最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。 Default:0-->
        <property name="maxIdleTime" value="60"/>
        <!-- 当连接池中的连接耗尽的时候c3p0一次同时获取的连接数. Default:3-->
        <property name="acquireIncrement" value="5"/>
        <!-- JDBC的标准,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements属于单个connection而不是整个连接池所以设置这个参数需要考虑到多方面的因数.如果maxStatements与maxStatementsPerConnection均为 0,则缓存被关闭。Default:0-->
        <property name="maxStatements" value="0"/>
        <!-- 每60秒检查所有连接池中的空闲连接.Default:0 -->
        <property name="idleConnectionTestPeriod" value="60"/>
        <!-- 定义在从数据库获取新连接失败后重复尝试的次数。 Default:30 -->
        <property name="acquireRetryAttempts" value="30"/>
        <!-- 获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试获取连接失败后该数据源将申明已断开并永久关闭。Default:false -->
        <property name="breakAfterAcquireFailure" value="true"/>
        <!-- 银性能消耗大请只在需要的时候是哟个它。如果设为true,那么在每个connection提交的时候都将校验其有效性。建议使用 idleConnectionTestPeriod或automaticTestTable等提升连接测试的性能。 Default:false-->
        <property name="testConnectionOnCheckout" value="false"/>
    </bean>
   
    <!-- 配置SessionFactory-->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <!-- 依赖注入 数据源-->
        <property name="dataSource" ref="dataSource"></property>
        <!-- 配置映射文件-->
        <property name="mappingResources">
            <list>
                <value>org/cric/model/NewMapping.hbm.xml</value>
            </list>
        </property>
        <!-- 配置hibernate属性-->
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
            </props>
        </property>
    </bean>
   
    <bean id="studentDao" class="org.cric.dao.impl.StudentDaoImpl">
        <!-- 依赖注入 -->
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
   
    <bean id="studentService" class="org.cric.service.impl.StudentServiceImpl">
        <!-- 依赖注入 -->
        <property name="studentDao" ref="studentDao"/>
    </bean>
   
</beans>
分享到:
评论

相关推荐

    spring 配置c3p0

    总结,Spring配置C3P0连接池涉及到添加依赖、在Spring配置文件中定义数据源bean以及配置C3P0的相关参数。通过这种方式,我们可以有效地管理和利用数据库连接,提高系统的稳定性和效率。在实际项目中,还需要根据具体...

    spring c3p0小例子

    总的来说,"spring c3p0小例子"是一个关于如何在Spring项目中集成C3P0连接池的示例,通过Maven管理依赖,配置C3P0数据源,以及创建和配置DAO来执行数据库操作。这个例子可以帮助开发者理解Spring与C3P0结合使用时的...

    c3p0jar包及配置文件(可用)

    内容概要:c3p0连接池需要jar包.rar以及相关配置文件 C3P0是一个开源的JDBC连接池,它实现了数据源和JNDI绑定,支持JDBC3规范和JDBC2的标准扩展。目前使用它的开源项目有Hibernate、Spring等。 适合人群:正在学习...

    c3p0连接池jar包以及Spring对c3p0的依赖包

    3. **连接池配置**:C3P0允许通过配置文件灵活设置各种参数,如初始化连接数、最大连接数、最小连接数、超时时间等。 4. **异常处理**:C3P0有完善的异常处理机制,当检测到数据库连接出现问题时,可以自动尝试重连...

    Spring通过c3p0配置bean连接数据库

    Spring 通过 C3P0 配置 Bean 连接数据库 Spring 框架是一种流行的 Java 应用程序框架,它提供了许多功能强大且灵活的特性,包括依赖注入、 AOP、MVC 等。其中,连接数据库是 Spring 应用程序中一个非常重要的环节。...

    C3P0连接池配置需要的jar包

    配置C3P0连接池时,开发者通常需要在配置文件(如Hibernate的`hibernate.cfg.xml`或Spring的`applicationContext.xml`)中指定以下参数: - `driver_class`: 数据库驱动类名,例如`com.mysql.jdbc.Driver`。 - `...

    c3p0配置mysql8.0.21的3个jar包

    2. **创建C3P0数据源**:在Java代码或配置文件(如Spring的`application.properties`或`context.xml`)中定义C3P0数据源。 ```java import com.mchange.v2.c3p0.ComboPooledDataSource; public class C3P0...

    SSH - SpringMVC4 + Spring4 + Hibernate4 + c3p0 + Mysql.zip

    在本项目"SSH - SpringMVC4 + Spring4 + Hibernate4 + c3p0 + Mysql.zip"中,开发者使用了SpringMVC4作为表现层,Spring4作为控制层和服务层,Hibernate4作为持久层,c3p0作为数据库连接池,以及MySQL作为数据库。...

    spring + c3p0 连接池

    然后,在Spring的配置文件(如`applicationContext.xml`)中添加C3P0的数据源配置: ```xml &lt;bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"&gt; &lt;!-- 更...

    c3p0-0.9.5.2及配置文件和mysql8驱动包.zip

    这个压缩包"**c3p0-0.9.5.2及配置文件和mysql8驱动包.zip**"包含了c3p0的0.9.5.2版本jar包以及适用于MySQL 8.x版本的驱动包,这是为了确保与较新版本的MySQL数据库兼容。 **c3p0** 是由Miquel Arroyo开发的一个轻量...

    c3p0配置及jar包

    在Spring中配置c3p0,通常需要在`applicationContext.xml`或对应的配置文件中添加以下内容: ```xml &lt;bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"&gt; &lt;!-- 配置c3p0连接池...

    springMVC整合C3P0连接池

    在Spring的配置文件(如`applicationContext.xml`)中,添加C3P0的数据源bean定义,例如: ```xml &lt;bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"&gt; &lt;!-- C3P0 连接池的配置...

    idea 使用spring自带的定时器quartz 使用的c3p0 v0.95.2所包含的jar

    集成`c3p0`到`Spring`项目中,你需要在`Spring`的配置文件中添加以下配置: ```xml &lt;bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"&gt; &lt;!-- 其他可配置参数 --&gt; ``` 接下来,...

    c3p0用法步骤

    综上所述,使用C3P0管理数据库连接的关键在于正确配置`init.properties`文件,以及将其与Spring框架集成,从而实现高效、稳定的数据库连接管理。这不仅能够显著提升应用的性能,还能简化数据库操作的复杂性,是Java ...

    C3P0使用,C3P0源码及实例

    除了资源文件配置外,C3P0也可以通过XML配置文件(如`c3p0-config.xml`)进行设置,这种方式更加灵活,可以针对不同的数据源设定不同的配置。例如: ```xml &lt;class-name&gt;...

    C3P0相关的JAR包

    在应用中使用C3P0,通常需要在配置文件(如`persistence.xml`或自定义的配置文件)中设置相关参数,包括最小连接数、最大连接数、初始化连接数、超时时间等。例如: ``` &lt;property name="c3p0....

    Spring +struts+c3p0 框架demo

    【Spring + Struts + C3P0 框架整合详解】 在软件开发领域,Spring、Struts 和 C3P0 是三个非常重要的开源框架,它们分别负责不同的职责,共同构建了一个高效、稳定的Web应用程序。Spring 作为核心的依赖注入(DI)...

    C3p0配置连接池及jar

    2. 配置数据源:在应用程序中创建C3p0数据源,通常在Spring框架中通过XML配置文件或者Java配置来实现。以下是一个基本的XML配置示例: ```xml &lt;bean id="dataSource" class="com.mchange.v2.c3p0....

Global site tag (gtag.js) - Google Analytics