Cannot get a connection, pool error Timeout waiting for idle object

   最近用SSH框架(Spring,HIberante,Struts2,GWT,extjs )开发管控系统,发现我开发的页面,在多次点击左侧的导航树时,会报:Cannot get a connection, pool error Timeout waiting for idle object 的错误

   咨询了同事后才发现,是我的@Controller 的名字有错误。在我们公司的这套SSH框架中,只对结尾为Service的类提供自动关闭连接的服务。所以我的解决方案为:

  (1)将

@Controller("moduleControllerServiceOfFY")
@Scope("prototype")
public class ModuleControllerServiceOfFY extends GwtCotroller{

修改为:

@Controller("moduleControllerService")
@Scope("prototype")
public class ModuleControllerServiceOfFY extends GwtCotroller{
	//也就是说,controller的名称必须是以Service结尾
<bean id="listModuleOfFYAction"
	class="com.jb.framework.struts.action.DispatcherAction"
			scope="prototype">
			<!-- moduleServiceOfFY  moduleControllerService -->
			<property name="service" ref="moduleControllerService"></property>
	</bean>


 

    查询数据时,Spring并不能够自动关闭连接,也就是说,在使用中这几句代码总是不断的获取数据库的连接,每调用一次就申请一个连接……直到 tomcat连接池中的连接耗尽……所以就再也申请不到连接了……于是,就出现了这个异常,解决办法是使用事务来管理这段代码,让Spring自动管理这段代码中申请的连接。

  查看我公司的代码,发现spring中的配置文件如下:

 

<!-- 配置事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
	</bean>

	<!-- 配置事务的传播特性 -->
	<bean id="transactionInterceptor"
		class="org.springframework.transaction.interceptor.TransactionInterceptor">
		<property name="transactionManager" ref="transactionManager" />
		<property name="transactionAttributes">
			<props>
				<prop key="save*">PROPAGATION_REQUIRED</prop>
				<prop key="mod*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="del*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="*">PROPAGATION_REQUIRED</prop>
			</props>
		</property>
	</bean>

	<bean
		class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
		<property name="proxyTargetClass">  
			<value>true</value>  
		</property>       
		<property name="beanNames">
			<value>*Service</value>
		</property>
		<property name="interceptorNames">
			<list>
				<value>transactionInterceptor</value>
			</list>
		</property>
	</bean>

	<bean
		class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
		<property name="transactionInterceptor"
			ref="transactionInterceptor" />
	</bean>
	<!-- 异常处理管理器 -->
	<bean id="excAdvisorTarget" class="com.jb.framework.exception.advisor.ExceptionAdvisor" >
		<property name="tbSysErrLogDao" ref="tbSysErrLogDao"></property>
	</bean>


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值