Springboot配置application.yml连接MySQL数据库

1.在pom.xml的<dependencies></dependencies>标签中中加入以下依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

   <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>

    <dependency>
        <groupId>com.alibaba</groupId>
       <artifactId>druid</artifactId>
         <version>1.1.10</version>
   </dependency>

把resource包下的application.properties复制一份再粘贴名字改成application.yml,加入以下内容
server:
port: 8080
servlet:
context-path: /
spring:
datasource:
username: root
password:
url: jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容