<dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.2.4</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency>
加入上面的两个依赖
第二步,书写application.yml
spring: datasource: druid: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc.mysql:///zhouyi2 #url: jdbc.mysql://127.0.0.1:3306/zhouyi2/useUnicode=true&characterEncoding=utf8&userSSL=true&serverTimezone=Asia/Shanghai #url: jdbc.mysql:///zhouyi2 username: root password: xxxxx initial-size: 10 min-idle: 10 max-active: 50 max-wait: 15000 #监控配置 stat-view-servlet: allow: 112.38.46.177 deny: url-pattern: /druid/* enabled: true login-username: system login-password: 123456 server: port: 80
不知为何,设置初始化连接数时总是报错。只有设置为0,才成功。目前的mysql的版本为5.0,明天升级到mysql5.7,试试。
原文:https://www.cnblogs.com/sdgtxuyong/p/14405693.html