application.yml配置数据库
时间: 2023-09-06 15:08:32 浏览: 339
在application.yml文件中配置数据库,需要添加以下配置项:
1. 首先,在spring节点下添加datasource节点,配置数据库连接信息。示例代码如下:
```
spring:
datasource:
url: jdbc:mysql://localhost:3306/test1?characterEncoding=utf-8&serverTimezone=GMT+8
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
```
这里的url是数据库的连接地址,username是数据库的用户名,password是数据库的密码,driver-class-name是数据库的驱动名称。
2. 接下来,在mybatis节点下添加mapper-locations和type-aliases-package配置项。示例代码如下:
```
mybatis:
mapper-locations: classpath:mapper/*Mapper.xml
type-aliases-package: com.test.elasticsearchdemo.domain
```
这里的mapper-locations是指定mapper映射xml文件的路径,type-aliases-package是指定实体类的路径。
通过以上配置项,可以成功配置数据库连接和MyBatis的相关配置。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [application.yml数据库配置](https://blog.csdn.net/m0_55578242/article/details/119027084)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [application.yml配置](https://blog.csdn.net/m0_57640092/article/details/121662146)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [SpringBoot项目application.yml文件数据库配置密码加密的方法](https://download.csdn.net/download/weixin_38702110/12727256)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文