<dependency>
<groupId>mysqlgroupId>
<artifactId>mysql-connector-javaartifactId>
<version>8.0.11version>
dependency>
spring:
datasource:
#注意下行比不是mysql8.0多一个cj.
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: 123456
url: jdbc:mysql://localhost:3306/recruit_gather?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
@SpringBootTest
class SpringDataJdbc06ApplicationTests {
@Autowired
DataSource dataSource;
@Test
void contextLoads() throws SQLException {
System.out.println("*******************");
System.out.println(dataSource.getClass());
Connection connection = dataSource.getConnection();
System.out.println("connection连接:"+connection);
}
}