SpringBoot之整合Druid数据源

1. 引入依赖

<!-- jdbc相关的依赖 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- druid数据源依赖 -->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-starter</artifactId>
    <version>1.2.16</version>
</dependency>
<!-- mysql数据库连接相关的依赖 -->
<dependency>
    <groupId>com.mysql</groupId>
    <artifactId>mysql-connector-j</artifactId>
    <scope>runtime</scope>
</dependency>

2. 在application.yml中添加数据源相关配置

spring:
  datasource:
    #durid数据源配置信息,包含驱动名称、连接url、用户名、密码等信息
    druid:
      driver-class-name: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://localhost:3306/life_assistant?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
      username: root
      password: root

3. 启动项目

posted @ 2023-04-06 18:11  安徒生敲代码  阅读(26)  评论(0编辑  收藏  举报