1、引入依赖,网址:https://mvnrepository.com/artifact/com.baomidou
这里最新版本为3.5.3.2,点击进去
2、在pom.xml中添加依赖,并确认依赖中已经有了mysql-connector-j的依赖
<!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.5.3.2</version> </dependency>
<!-- https://mvnrepository.com/artifact/com.mysql/mysql-connector-j --> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <version>8.1.0</version> </dependency>
3、在application.yml文件中配置数据源
spring: datasource: url: jdbc:mysql://localhost:3306/boottest?useSSL=false&serverTimezone=UTC&useUnicode=true&characterEncoding=utf8 username: root password: 123456
4、编写测试类
@Resource //不用要@Autowired DataSource dataSource; @Test void contextLoads() throws Exception { System.out.println(dataSource.getClass()); System.out.println(dataSource.getConnection()); }
输出结果为
标签:依赖,plus,SpringBoot3,mysql,Mybatis,com,dataSource From: https://www.cnblogs.com/windok/p/17631845.html