Druid is a database connection pool first, but it is not just a database connection pool. It also contains a proxydriver, a series of built-in JDBC component libraries, and an SQL parser.
Add the following configuration section in the Pom. xml file --
1 <dependency>2 <groupId>com.alibaba</groupId>3 <artifactId>druid</artifactId>4 <version>${druid-version}</version>5 </dependency>
- Spring data source configuration
Add the following configuration section in the spring configuration file --
1 <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> 2 <property name="url" value="${jdbc_url}" /> 3 <property name="username" value="${jdbc_user}" /> 4 <property name="password" value="${jdbc_password}" /> 5 6 <property name="filters" value="stat" /> 7 8 <property name="maxActive" value="20" /> 9 <property name="initialSize" value="1" /> 10 <property name="maxWait" value="60000" /> 11 <property name="minIdle" value="1" /> 12 13 <property name="timeBetweenEvictionRunsMillis" value="60000" /> 14 <property name="minEvictableIdleTimeMillis" value="300000" /> 15 16 <property name="validationQuery" value="SELECT ‘x‘" /> 17 <property name="testWhileIdle" value="true" /> 18 <property name="testOnBorrow" value="false" /> 19 <property name="testOnReturn" value="false" /> 20 21 <property name="poolPreparedStatements" value="true" /> 22 <property name="maxPoolPreparedStatementPerConnectionSize" value="50" /> 23 </bean>
- Web Monitoring page configuration
Add the following configuration section in Web. XML to perform monitoring through http: // {IP }:{ port}/druid.
1 <servlet>2 <servlet-name>DruidStatView</servlet-name>3 <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>4 </servlet>5 <servlet-mapping>6 <servlet-name>DruidStatView</servlet-name>7 <url-pattern>/druid/*</url-pattern>8 <servlet-mapping>
View code
Druid connection pool