时间:2021-07-01 10:21:17 帮助过:5人阅读
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