数据库连接 长时间空闲 断开连接
solution:

<property name="validationQuery" value="select 1"/>    <!-- 执行没有实际意义的sql -->
<property name="testWhileIdle" value="true" />
<property name="removeAbandoned" value="true"/>

.\src\main\resources\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:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd" xmlns:aop="http://www.springframework.org/schema/aop"> <description>Spring公共配置 </description> <context:property-placeholder ignore-unresolvable="true" file-encoding="utf-8"
location="classpath:config.properties,classpath:jdbc.properties" /> <!-- 使用annotation 自动注册bean, 并保证@Required、@Autowired的属性被注入 -->
<context:component-scan base-package="com.tsinghuadtv.www" use-default-filters="true">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan> <!-- 使用annotation定义事务 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" /> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:mybatis/config.xml"/>
<property name="mapperLocations" value="classpath*:mybatis/mappers/**/*.xml"/>
<property name="typeHandlers" value="#{getObject('typeHandlers')}" />
</bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.tsinghuadtv.www.mapper" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory"/>
</bean> <!-- 数据源配置, 使用Tomcat JDBC连接池 -->
<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
<!-- Connection Info -->
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" /> <!-- Connection Pooling Info -->
<property name="maxActive" value="${jdbc.pool.maxActive}" />
<property name="maxIdle" value="${jdbc.pool.maxIdle}" />
<property name="minIdle" value="10" />
<property name="defaultAutoCommit" value="false" />
<property name="validationQuery" value="select 1"/>
<property name="testWhileIdle" value="true" />
<property name="removeAbandoned" value="true"/>
</bean> <!-- 配置jdbcTemplate -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean> <bean class="com.tsinghuadtv.www.model.filter.OrderByBuilder">
<property name="configFile" value="classpath:mybatis/PropertyColumnMapping.xml"/>
</bean> <!-- 定时任务annotation驱动 -->
<task:annotation-driven/> </beans>

  

.\src\main\resources\jdbc.properties

jdbc.driver=com.mysql.jdbc.Driver

jdbc.url=jdbc:mysql://127.0.0.1/dbname?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&allowMultiQueries=true
jdbc.username=root
jdbc.password= #connection pool settings
jdbc.pool.maxIdle=20
jdbc.pool.maxActive=300

  

jdbc 数据库连接 长时间空闲 断开连接 ApplicationContext.xml的更多相关文章

  1. 解决ssh登录后闲置时间过长而断开连接

     ++++++++++++++++++++++++++++ #!/usr/bin/env bash password_5="Uxxx7"host_5="129.x.x.1 ...

  2. [转]解决ssh登录后闲置时间过长而断开连接

    本文转自: 转载自博客园wanghetao的博客 我们通过终端连接服务器时,当鼠标和键盘长时间不操作,服务器就会自动断开连接,我们还的需要重新连接,感觉很麻烦,总结一下解决此问题的方法 方法一 修改/ ...

  3. 保持ssh连接长时间不断开的技巧

    我经常用ssh连接服务器,过段时间不用, 需要恢复一下断开的连接, 原因是NAT防火墙喜欢对空闲的会话进行超时处理,以确保它们状态表的干净和内存的低占用率,因为 长时间保持连接, 会长期占用部分系统资 ...

  4. .net跨防火墙链接oracle连接池链接长时间无通讯数据被断开后报错问题解决

    环境: .net 4.0以上使用Oracle.ManagedDataAccess组件链接oracle数据库,应用程序与数据库之间存在硬件防火墙. 症状:应用程序启动后正常访问,如果出现长时间无数据库请 ...

  5. 想要远程服务器长时间挂机不断开ssh连接的技巧

    使用top命令挂着就好了,top命令执行的“查看系统进程和资源占用”的任务会一直输出动态的数据,一直有数据传输就不会因为长时间挂机而断开ssh链接了,尤其针对于海外服务器,因为高延迟经常出现挂机久了自 ...

  6. SSH连接服务器时,长时间不操作就会断开的解决方案

    最近在配置服务器相关内容时候,不同的事情导致长时间不操作,页面就断开了连接,不能操作,只能关闭窗口,最后通过以下命令解决. SSH连接linux时,长时间不操作就断开的解决方案: 1.修改/etc/s ...

  7. 长时间没有操作putty就会断开连接是怎么回事?

    seconds between keepalives 设置为10就好了, 这个值有什么含义,服务器为了节省资源采取了一些措施,其中一条就是如果检测一个会话(session)几分钟或者几小时没有数据流入 ...

  8. Linux 长时间操作设置不断开

    1.第一次尝试失败 修改/etc/ssh/sshd_config文件, 找到 ClientAliveInterval 0 ClientAliveCountMax 3 并将注释符号("#&qu ...

  9. mysql在空闲8小时之后会断开连接(默认情况)

    调试程序的过程发现,在mysql连接空闲一定时间(默认8小时)之后会断开连接,需要重新连接,也引发我对重连机制的思考.

随机推荐

  1. 005 媒体访问控制(MAC,Media Access Control)

    一,MAC MAC是媒体访问控制器.以太网MAC由IEEE-802.3以太网标准定义.它实现了数据链路层.最新的MAC同时支持10/100/1000Mbps速率.通常情况下,它实现MII/GMII/R ...

  2. Python数学建模系列(一):规划问题之线性规划

    @ 目录 前言 线性规划 样例1:求解下列线性规划问题 scipy库求解 样例2:求解下列线性规划问题 pulp库求解 样例3.运输问题 说明 结语 前言 Hello!小伙伴! 非常感谢您阅读海轰的文 ...

  3. NOIP 模拟 $31\; \rm Time$

    题解 \(by\;zj\varphi\) 考虑如何才能最优. 每次一定把当前最小值移动到边界上,那么看它向左还是向右移更优. 用树状数组维护一下即可,复杂度 \(\mathcal O\rm (nlog ...

  4. SpringBoot枚举传参

    创建一个接口所有枚举继承 package com.gecko.charging.common; public interface BaseEnum { Integer getCode(); } 具体的 ...

  5. HCNP Routing&Switching之OSPF网络类型

    前文我们了解了PPPoE协议相关话题,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/15182512.html:今天我们聊聊一聊OSPF中的网络类型相关话题: ...

  6. DOS创建/删除/描述 windows服务

    1.以管理员运行cmd ,输入 sc create test binPath= 程序路径\xxx.exe,主要 "="后面必须要空格 在服务里面查看结果 2.设置服务格式: sc ...

  7. 【springboot】知识点总结

    [springboot 基础编] 01.SpringBoot>01 - 第一个应用–HelloWorld 02.SpringBoot>02 - 整合 MyBatis 03.SpringBo ...

  8. COM笔记-动态链接

    在实现了IUnknown之后,组件和客户之间只是一种非常松散的连接,这使用组件和客户各自可以发生变化而不会对对方造成什么影响. 下面讨论如何将组件放入到动态链接库(dll)中. 关于DLL更多内容可以 ...

  9. 【springcloud alibaba】配置中心之nacos

    接着上一篇的[springcloud alibaba]注册中心之nacos,这一篇主要讲nacos的配置中心能力.nacos的集群部署及持久化请看上一篇. ---------------------- ...

  10. springboot:嵌套使用异步注解@Async还会异步执行吗

    一.引言 在前边的文章<[springboot:使用异步注解@Async的那些坑>中介绍了使用@Async注解获取任务执行结果的错误用法,今天来分享下另外一种常见的错误. 二.代码演示 下 ...