spring配置C3P0问题
服务器运行几天后就会出现连不了数据库,不知道具体的问题所在。
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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass"><value>oracle.jdbc.OracleDriver</value></property>
<property name="jdbcUrl"><value>jdbc:oracle:thin:@192.68.69.1:1521:orcl</value></property>
<property name="user"><value>admin</value></property>
<!-- Make sure <value> tags are on same line - if they're not, authentication will fail -->
<property name="password"><value>admin</value></property>
<!--连接池中保留的最小连接数。-->
<property name="minPoolSize">
<value>5</value>
</property>
<!--连接池中保留的最大连接数。Default: 15 -->
<property name="maxPoolSize">
<value>30</value>
</property>
<!--初始化时获取的连接数,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
<property name="initialPoolSize">
<value>10</value>
</property>
<!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
<property name="maxIdleTime">
<value>60</value>
</property>
<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
<property name="acquireIncrement">
<value>5</value>
</property>
<!--JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements
属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。
如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0-->
<property name="maxStatements">
<value>0</value>
</property>
<!--每60秒检查所有连接池中的空闲连接。Default: 0 -->
<property name="idleConnectionTestPeriod">
<value>60</value>
</property>
<!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 -->
<property name="acquireRetryAttempts">
<value>30</value>
</property>
<!--获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效
保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试
获取连接失败后该数据源将申明已断开并永久关闭。Default: false-->
<property name="breakAfterAcquireFailure">
<value>false</value>
</property>
<property name="acquireRetryDelay">
<value>100</value>
</property>
<!--因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的
时候都将校验其有效性。建议使用idleConnectionTestPeriod或automaticTestTable
等方法来提升连接测试的性能。Default: false -->
<property name="testConnectionOnCheckout">
<value>false</value>
</property>
</bean>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource"><ref local="dataSource"/></property>
<property name="mappingResources">
<list>
<value>com/xtbg/web/domain/TExchangeProj.hbm.xml</value>
<value>com/xtbg/web/domain/TBaseProj.hbm.xml</value>
....等等。。。
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">none</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<!-- transaction config -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
<!-- 系统管理模块配置 -->
<bean id="departmentDAO" class="com.xtbg.web.dao.DepartmentDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="employeeDAO" class="com.xtbg.web.dao.EmployeeDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="powerDAO" class="com.xtbg.web.dao.PowerDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="roleDAO" class="com.xtbg.web.dao.RoleDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="rolePowerDAO" class="com.xtbg.web.dao.RolePowerDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 信息办模块配置 -->
<bean id="baseProjDAO" class="com.xtbg.web.dao.BaseProjDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="projMemberDAO" class="com.xtbg.web.dao.ProjMemberDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="projAttachmentDAO" class="com.xtbg.web.dao.ProjAttachmentDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="sbsqxxDAO" class="com.xtbg.web.dao.SbsqxxDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="sbslxxDAO" class="com.xtbg.web.dao.SbslxxDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="sbspxxDAO" class="com.xtbg.web.dao.SbspxxDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="projCodeDAO" class="com.xtbg.web.dao.ProjCodeDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="exchangeProjDAO" class="com.xtbg.web.dao.ExchangeProjDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="zjysghDAO" class="com.xtbg.web.dao.ZjysghDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- service配置 -->
<bean id="systemService" class="com.xtbg.web.service.impl.SystemService">
<property name="departmentDAO" ref="departmentDAO"/>
<property name="employeeDAO" ref="employeeDAO"/>
<property name="powerDAO" ref="powerDAO"/>
<property name="roleDAO" ref="roleDAO"/>
<property name="rolePowerDAO" ref="rolePowerDAO"/>
</bean>
<!-- AOP事务 -->
<aop:config>
<aop:pointcut id="serviceOperation" expression="execution(* com.xtbg.web.service.impl.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" />
<tx:method name="delete*" />
<tx:method name="search*" />
<tx:method name="submit*" />
<tx:method name="download*" />
</tx:attributes>
</tx:advice>
</beans>
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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass"><value>oracle.jdbc.OracleDriver</value></property>
<property name="jdbcUrl"><value>jdbc:oracle:thin:@192.68.69.1:1521:orcl</value></property>
<property name="user"><value>admin</value></property>
<!-- Make sure <value> tags are on same line - if they're not, authentication will fail -->
<property name="password"><value>admin</value></property>
<!--连接池中保留的最小连接数。-->
<property name="minPoolSize">
<value>5</value>
</property>
<!--连接池中保留的最大连接数。Default: 15 -->
<property name="maxPoolSize">
<value>30</value>
</property>
<!--初始化时获取的连接数,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
<property name="initialPoolSize">
<value>10</value>
</property>
<!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
<property name="maxIdleTime">
<value>60</value>
</property>
<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
<property name="acquireIncrement">
<value>5</value>
</property>
<!--JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements
属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。
如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0-->
<property name="maxStatements">
<value>0</value>
</property>
<!--每60秒检查所有连接池中的空闲连接。Default: 0 -->
<property name="idleConnectionTestPeriod">
<value>60</value>
</property>
<!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 -->
<property name="acquireRetryAttempts">
<value>30</value>
</property>
<!--获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效
保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试
获取连接失败后该数据源将申明已断开并永久关闭。Default: false-->
<property name="breakAfterAcquireFailure">
<value>false</value>
</property>
<property name="acquireRetryDelay">
<value>100</value>
</property>
<!--因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的
时候都将校验其有效性。建议使用idleConnectionTestPeriod或automaticTestTable
等方法来提升连接测试的性能。Default: false -->
<property name="testConnectionOnCheckout">
<value>false</value>
</property>
</bean>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource"><ref local="dataSource"/></property>
<property name="mappingResources">
<list>
<value>com/xtbg/web/domain/TExchangeProj.hbm.xml</value>
<value>com/xtbg/web/domain/TBaseProj.hbm.xml</value>
....等等。。。
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">none</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<!-- transaction config -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
<!-- 系统管理模块配置 -->
<bean id="departmentDAO" class="com.xtbg.web.dao.DepartmentDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="employeeDAO" class="com.xtbg.web.dao.EmployeeDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="powerDAO" class="com.xtbg.web.dao.PowerDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="roleDAO" class="com.xtbg.web.dao.RoleDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="rolePowerDAO" class="com.xtbg.web.dao.RolePowerDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 信息办模块配置 -->
<bean id="baseProjDAO" class="com.xtbg.web.dao.BaseProjDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="projMemberDAO" class="com.xtbg.web.dao.ProjMemberDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="projAttachmentDAO" class="com.xtbg.web.dao.ProjAttachmentDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="sbsqxxDAO" class="com.xtbg.web.dao.SbsqxxDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="sbslxxDAO" class="com.xtbg.web.dao.SbslxxDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="sbspxxDAO" class="com.xtbg.web.dao.SbspxxDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="projCodeDAO" class="com.xtbg.web.dao.ProjCodeDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="exchangeProjDAO" class="com.xtbg.web.dao.ExchangeProjDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="zjysghDAO" class="com.xtbg.web.dao.ZjysghDAO" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- service配置 -->
<bean id="systemService" class="com.xtbg.web.service.impl.SystemService">
<property name="departmentDAO" ref="departmentDAO"/>
<property name="employeeDAO" ref="employeeDAO"/>
<property name="powerDAO" ref="powerDAO"/>
<property name="roleDAO" ref="roleDAO"/>
<property name="rolePowerDAO" ref="rolePowerDAO"/>
</bean>
<!-- AOP事务 -->
<aop:config>
<aop:pointcut id="serviceOperation" expression="execution(* com.xtbg.web.service.impl.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" />
<tx:method name="delete*" />
<tx:method name="search*" />
<tx:method name="submit*" />
<tx:method name="download*" />
</tx:attributes>
</tx:advice>
</beans>
...全文
相关推荐
c3p0连接池jar包以及Spring对c3p0的依赖包
**异常处理**:C3P0有完善的异常处理机制,当检测到数据库连接出现问题时,可以自动尝试重连或者关闭问题连接。
详解springboot 使用c3p0数据库连接池的方法
小结在本文中,我们详细介绍了如何在 Spring Boot 应用程序中使用 C3P0 数据库连接池。C3P0 提供了高性能、可靠性和可扩展性,解决了数据库连接中断的问题。
C3P0连接池+MySQL的配置及wait_timeout问题的解决方法
本文主要探讨了在Spring 4.2.4、MyBatis 3.2.8、C3P0 0.9.1.2和MySQL 5.6.24的环境中如何配置C3P0连接池,以及遇到wait_timeout问题的解决策略。
Spring +struts+c3p0 框架demo
首先,引入相关的jar包,包括Spring、Struts、C3P0以及它们的依赖库。2. 配置Spring的bean定义文件,声明需要管理的对象及它们之间的依赖关系。
webwork+ibatis+spring oracle c3p0 集成框架
配置C3P0数据源:在Spring配置文件中添加C3P0的数据源配置,包括数据库连接参数如URL、用户名、密码等,以及C3P0的特定配置项如最大连接数、最小连接数等。2.


