1.整合mybatis
1.1 pom.xml中引入maven配置
1.2在application.properties中配置核心
mybatis:
mapper-locations: classpath:mapping/*Mapper.xml
type-aliases-package: com.example.entity
2.整合druid
springboot已经默认使用了 HikariCP 连接池。一般不用换
2.1 pom.xml中引入maven配置
druid有两种配置,pom
依赖有两个版本,一个需要编写配置文件,一个是自动配置的
下面是自动配置(带有spring-boot),就是只需要在application.properties中进制配置即可。
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.21</version>
</dependency>
application.properties配置
server: port: 8888 spring: application: name: springboot-druid datasource: username: root password: 123456 url: jdbc:mysql://localhost:3306/spring-boot-test?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC driver-class-name: com.mysql.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource # 数据库连接池类别 druid: initial-size: 5 # 初始化大小 min-idle: 10 # 最小连接数 max-active: 20 # 最大连接数 max-wait: 60000 # 获取连接时的最大等待时间 min-evictable-idle-time-millis: 300000 # 一个连接在池中最小生存的时间,单位是毫秒 time-between-eviction-runs-millis: 60000 # 多久才进行一次检测需要关闭的空闲连接,单位是毫秒 filters: stat,wall # 配置扩展插件:stat-监控统计,log4j-日志,wall-防火墙(防止SQL注入),去掉后,监控界面的sql无法统计 validation-query: SELECT 1 # 检测连接是否有效的 SQL语句,为空时以下三个配置均无效 test-on-borrow: true # 申请连接时执行validationQuery检测连接是否有效,默认true,开启后会降低性能 test-on-return: true # 归还连接时执行validationQuery检测连接是否有效,默认false,开启后会降低性能 test-while-idle: true # 申请连接时如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效,默认false,建议开启,不影响性能 stat-view-servlet: enabled: true # 是否开启 StatViewServlet allow: 127.0.0.1 # 访问监控页面 白名单,默认127.0.0.1 deny: 192.168.56.1 # 访问监控页面 黑名单 login-username: admin # 访问监控页面 登陆账号 login-password: admin # 访问监控页面 登陆密码 filter: stat: enabled: true # 是否开启 FilterStat,默认true log-slow-sql: true # 是否开启 慢SQL 记录,默认false slow-sql-millis: 5000 # 慢 SQL 的标准,默认 3000,单位:毫秒 merge-sql: false # 合并多个连接池的监控数据,默认false # mybatis配置 mybatis: mapper-locations: classpath:mapper/*Mapper.xml type-aliases-package: com.dandelion.model # 输出sql语句日志 logging: level: com: springboot: dao: debug