(1)在application.properties中加入datasouce的配置
(2)在pom.xml加入mysql的依赖。
(3)获取DataSouce的Connection进行测试。
[注意]:配置mysql的编码,否则数据插入时可能会乱码或者中文不显示!
src/main/resouces/application.properties:
spring.datasource.url = jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false&maxReconnects=5
spring.datasource.username = root
spring.datasource.password = root
spring.datasource.driverClassName = com.mysql.jdbc.Driver
spring.datasource.max-active=20
spring.datasource.max-idle=8
spring.datasource.min-idle=8
spring.datasource.initial-size=10
mysql依赖引入
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.43</version>
</dependency>