How do Mybatis configure connection pooling

  • 2020-05-24 05:36:12
  • OfStack

The code is as follows:


<!--  Configure data source  -->
  <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
    <!--  Basic attributes  url , user , password --> 
    <property name="driverClassName" value="com.mysql.jdbc.Driver" /> 
    <property name="url" value="jdbc:mysql://localhost:3306/ssmhello" /> 
    <property name="username" value="root" /> 
    <property name="password" value="2424246258" /> 
    <property name="initialSize" value="1" /> 
    <property name="minIdle" value="1" />  
    <property name="maxActive" value="20" /> 
    <property name="maxWait" value="60000" />
    <!--  Whether to recycle after the time limit  -->
    <property name="removeAbandoned" value="true" />
    <!--  How long the time limit is exceeded;  -->
    <property name="removeAbandonedTimeout" value="180" />
    <!--  How long is the configuration interval 1 A secondary detection that detects idle connections that need to be closed in milliseconds  -->
    <property name="timeBetweenEvictionRunsMillis" value="60000" />
    <!--  configuration 1 The minimum time a connection can live in a pool, in milliseconds  -->
    <property name="minEvictableIdleTimeMillis" value="300000" />
    <!--  Used to check if the connection is valid sql , the requirement is 1 Query statement -->
    <property name="validationQuery" value="SELECT 1" />
    <!--  Check when applying for connection  -->
    <property name="testWhileIdle" value="true" />
    <!--  Execute when requesting a connection validationQuery Check if the connection is valid, configure as true It will degrade performance  -->
    <property name="testOnBorrow" value="false" />
    <!--  When the connection is returned validationQuery Check if the connection is valid, configure as true It will degrade performance  -->
    <property name="testOnReturn" value="false" />
  </bean>

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"> 

Of this label class The connection pool is already configured

What is used here is the current popular alibaba druid connection pool, which is just the class that USES the connection pool


Related articles: