spring配置C3P0问题

panqunjun panqunjun 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
服务器运行几天后就会出现连不了数据库,不知道具体的问题所在。
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>


...全文

相关推荐

评论 18
收藏 已收藏
分享
返回顶部
panqunjun
Java EE 67,535 成员 225,843 内容