druid是阿里巴巴开源的一款数据库连接池,性能很好,也有可视化的查询语句执行查看面板。
在pom.xml文件中添加druid的依赖,添加log4j的依赖,不加的话启动会报错,druid有用到它。
pom.xml
文件中添加druid连接池依赖,如下所示:
4.0.0
com.jmccms
Jmccms
0.0.1-SNAPSHOT
Jmccms
https://repo.spring.io/milestone
CYJ:ChenYongJia 服务提供者Jmccms
org.springframework.boot
spring-boot-starter-parent
2.1.5.RELEASE
UTF-8
UTF-8
1.8
5.1.39
4.12
1.1.20
1.2.17
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-actuator
org.springframework.boot
spring-boot-starter-aop
org.springframework.boot
spring-boot-starter-data-jpa
org.springframework.boot
spring-boot-starter-test
test
junit
junit
org.springframework.boot
spring-boot-starter-data-redis
com.alibaba
druid
${druid}
log4j
log4j
${log4j}
mysql
mysql-connector-java
${mysql-connector}
org.projectlombok
lombok
true
org.apache.httpcomponents
httpclient
4.5.8
org.springframework.boot
spring-boot-maven-plugin
jmccms
resource
包下创建application.yml
,加入以下内容:server:
#项目端口号
port: 8066
servlet:
context-path: /Jmccms # 项目访问路径
tomcat:# 优化tomcat
max-connections: 200
max-http-post-size: 0
max-threads: 300
min-spare-threads: 0
uri-encoding: UTF-8
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/jmccms?useUnicode=true&characterEncoding=UTF-8&useSSL=false
username: root
password: root
#集中解决各种编码问题
banner:
charset: UTF-8
http:
encoding:
charset: UTF-8
enabled: true
force: true
messages:
encoding: UTF-8
# spring mvc 视图解析器
mvc:
view:
prefix: /
suffix: .html
# 时间格式化
jackson:
date-format: yyyy-MM-dd HH:mm:ss
# 时区设置
time-zone: GMT+8
大家自行测试,我的数据库密码是root
,数据库名是jmccms
更多参考精彩博文请看这里:《陈永佳的博客》
喜欢博主的小伙伴可以加个关注、点个赞哦,持续更新嘿嘿!