## 引入pom.xml文件
```
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.29</version>
</dependency>
```
## 修改appcalition.properties文件
```
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
spring.datasource.initialSize=5
spring.datasource.minIdle= 5
spring.datasource.maxActive= 20
spring.datasource.maxWait= 60000
spring.datasource.timeBetweenEvictionRunsMillis= 60000
spring.datasource.minEvictableIdleTimeMillis= 300000
spring.datasource.validationQuery= SELECT 1 FROM DUAL
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=false
spring.datasource.testOnReturn=false
spring.datasource.poolPreparedStatements=false
spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
spring.datasource.filters= stat,wall,log4j
spring.datasource.connectionProperties= 'druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000'
```
## 新建DruidConfiguration配置类
```
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import javax.sql.DataSource;
import java.sql.SQLException;
/**
* 文件描述:
* 创建用户:emotion
* 创建时间:2019/6/20
*/
@Configuration
public class DruidConfiguration {
@Value("${spring.datasource.url}")
private String url;
@Value("${spring.datasource.username}")
private String username;
@Value("${spring.datasource.password}")
private String password;
@Value("${spring.datasource.driverClassName}")
private String driverClassName;
@Value("${spring.datasource.initialSize}")
private int initialSize;
@Value("${spring.datasource.minIdle}")
private int minIdle;
@Value("${spring.datasource.maxActive}")
private int maxActive;
@Value("${spring.datasource.maxWait}")
private int maxWait;
@Value("${spring.datasource.timeBetweenEvictionRunsMillis}")
private int timeBetweenEvictionRunsMillis;
@Value("${spring.datasource.minEvictableIdleTimeMillis}")
private int minEvictableIdleTimeMillis;
@Value("${spring.datasource.validationQuery}")
private String validationQuery;
@Value("${spring.datasource.testWhileIdle}")
private boolean testWhileIdle;
@Value("${spring.datasource.testOnBorrow}")
private boolean testOnBorrow;
@Value("${spring.datasource.testOnReturn}")
private boolean testOnReturn;
@Value("${spring.datasource.poolPreparedStatements}")
private boolean poolPreparedStatements;
@Value("${spring.datasource.maxPoolPreparedStatementPerConnectionSize}")
private int maxPoolPreparedStatementPerConnectionSize;
@Value("${spring.datasource.filters}")
private String filters;
@Value("${spring.datasource.connectionProperties}")
private String connectionProperties;
@Bean
@Primary
public DataSource dataSource(){
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl(url);
dataSource.setUsername(username);
dataSource.setPassword(password);
dataSource.setDriverClassName(driverClassName);
//configuration
dataSource.setInitialSize(initialSize);
dataSource.setMinIdle(minIdle);
dataSource.setMaxActive(maxActive);
dataSource.setMaxWait(maxWait);
dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
dataSource.setValidationQuery(validationQuery);
dataSource.setTestWhileIdle(testWhileIdle);
dataSource.setTestOnBorrow(testOnBorrow);
dataSource.setTestOnReturn(testOnReturn);
dataSource.setPoolPreparedStatements(poolPreparedStatements);
dataSource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
try {
dataSource.setFilters(filters);
} catch (SQLException e) {
}
dataSource.setConnectionProperties(connectionProperties);
return dataSource;
}
}
```
- JDK常用知识库
- JDK各个版本安装
- Java8流
- 算法
- 十大排序算法
- 冒泡排序
- 选择排序
- 插入排序
- 归并排序
- 快速排序
- 堆排序
- 希尔排序
- 计数排序
- 桶排序
- 基数排序
- 总结
- 常用工具类
- 浮点型计算
- 时间格式处理
- 常用功能点思路整理
- 登录
- 高并发
- 线程安全的单例模式
- Tomcat优化
- Tomcat之APR模式
- Tomcat启动过慢问题
- 常用的数据库连接池
- Druid连接池
- 缓存
- Redis
- SpringBoot整合Redis
- 依赖和配置
- RedisTemplate工具类
- 工具类使用方法
- Redis知识库
- Redis安装
- Redis配置参数
- Redis常用Lua脚本
- MongoDB
- SpringBoot操作MongoDB
- 依赖和配置
- MongoDB工具类
- 工具类使用方法
- 消息中间件
- ActiveMq
- SpringBoot整合ActiveMq
- 框架
- SpringBoot
- 定时任务
- 启动加载
- 事务
- JSP
- 静态类注入
- SpringSecurity
- Shiro
- 配置及整合
- 登陆验证
- 权限验证
- 分布式应用
- SpringMVC
- ORM框架
- Mybatis
- 增
- 删
- 改
- 查
- 程序员小笑话
- 我给你讲一个TCP的笑话吧
- 二进制笑话
- JavaScript的那点东西
- JavaScript内置对象及常见API详细介绍
- JavaScript实现Ajax 资源请求
- JavaScript干货
- 架构师成长之路
- JDK源码解析
- ArrayList源码解读
- 设计模式
- 微服务架构设计模式
- 逃离单体炼狱
- 服务的拆分策略
- 全面解析SpringMvc框架
- 架构设计的六大原则
- 并发集合
- JUC并发编程
- 搜索引擎
- Solr
- Solr的安装
- 分布式服务框架
- Dubbo
- 从零开始学HTMl
- 第一章-初识HTML
- 第二章-认识HTML标签