标签:-name import name red lse version beans ring jdbc
首次spring boot 配置 ,测试通过jdbc ,连接mysql8.0.1
1:pom.xml
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.11</version> </dependency>
2:application.yml
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
3:测试类代码
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); } }
4:正确显示结果
原创: spring boot5 与 mysql8 正确连接
标签:-name import name red lse version beans ring jdbc
原文地址:https://www.cnblogs.com/asplover/p/13369675.html