springboot整合mybatis+mysql+druid数据源
- 导入依赖包
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!--druid数据源 start-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.16</version>
</dependency>
<!--druid数据源 end-->
- 在pom.xml文件中添加如下
<!--maven打包的时候就会将src/main/java和src/main/resources相同包下的文件合并到同一包中-->
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
- 在application.yml中添加配置
spring:
datasource:
url: jdbc:mysql://39.97.234.52:3306/LearnWeb?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=Asia/Shanghai
username: root
password: root
type: com.alibaba.druid.pool.DruidDataSource
- 在启动类上添加注解@MapperScan注解,扫描mapper.xml文件所在的位置
@SpringBootApplication
@MapperScan("com.example.vueblog.mapper")
public class VueblogApplication {
public static void main(String[] args) {
SpringApplication.run(VueblogApplication.class, args);
}
}
springboot整合mybatis+mysql+druid数据源