From 30e2f1d44e443f8d582f2670da17eed67e85ea0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=80=E6=BA=90=E6=B5=B7=E5=93=A5?= Date: Mon, 24 Apr 2023 16:55:08 +0800 Subject: [PATCH] update docs --- docs/.vitepress/config.ts | 2 +- .../{mybatis-flex-with-spring.md => faq.md} | 64 +++++++++++++------ 2 files changed, 46 insertions(+), 20 deletions(-) rename docs/zh/{mybatis-flex-with-spring.md => faq.md} (56%) diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 0bd20fed..84a69a42 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -14,6 +14,7 @@ export default defineConfig({ nav: [ {text: '首页', link: '/'}, {text: '帮助文档', link: '/zh/what-is-mybatisflex'}, + {text: '常见问题', link: '/zh/faq'}, { text: '周边', items: [ {text: '示例代码', link: 'https://gitee.com/mybatis-flex/mybatis-flex-samples'}, @@ -37,7 +38,6 @@ export default defineConfig({ {text: 'Maven 依赖', link: '/zh/maven'}, {text: '和同类框架「功能」对比', link: '/zh/comparison'}, {text: '和同类框架「性能」对比', link: '/zh/benchmark'}, - {text: '和 Spring 整合 常见问题', link: '/zh/mybatis-flex-with-spring'}, {text: '支持的数据库类型', link: '/zh/support-database'}, {text: '使用 Mybatis 原生功能', link: '/zh/use-mybatis-native'}, {text: 'QQ 交流群', link: '/zh/qq-group'}, diff --git a/docs/zh/mybatis-flex-with-spring.md b/docs/zh/faq.md similarity index 56% rename from docs/zh/mybatis-flex-with-spring.md rename to docs/zh/faq.md index 2c8e2fd1..2da364c8 100644 --- a/docs/zh/mybatis-flex-with-spring.md +++ b/docs/zh/faq.md @@ -1,32 +1,38 @@ -# Mybatis-Flex 和 Spring 整合 +# 常见问题 -最近,看到群里有许多用户,用 MyBatis-Flex 整合 Spring 的时候遇到了一些问题,这个文档再补充说明一下。 +## 示例中的 AccountMapper 和 "ACCOUNT" 在哪里,报错了。 -在开始使用 Mybatis-Flex 之前,可以先看一下 MyBatis-Flex-Samples 示例,网址为: -[https://gitee.com/mybatis-flex/mybatis-flex-samples](https://gitee.com/mybatis-flex/mybatis-flex-samples)。 +Mybatis-Flex 使用了 APT 技术,这两个类是自动生成的。 +参考:[Mybatis-Flex APT 配置 - Mybatis-Flex 官方网站](./apt.md) -## 常见问题 -**问题1: 使用 Druid 数据源无法启动** +## SpringBoot 项目,启动报错 Property 'sqlSessionFactory' or 'sqlSessionTempalte' are required -原因是在数据源的配置中,未添加 `type` 字段的配置: +如果当前依赖没有连接池相关依赖,则建议添加 HikariCP 依赖。 +如果已经添加了如 druid 依赖,则配置数据源类型 `spring.datasource.type=com.alibaba.druid.pool.DruidDataSource`。 -```yaml 3 -spring: - datasource: - type: com.alibaba.druid.pool.DruidDataSource - url: jdbc:mysql://127.0.0.1:3306/dbtest - username: root - password: 123456 +SpringBoot v2.x 添加 hikariCP 的内容如下: + +```xml + + com.zaxxer + HikariCP + 4.0.3 + ``` -第 3 行中的 `type` 字段不能为空,这个并非是 MyBaits-Flex 的问题,而是 Spring 没有内置对 Druid 数据源类型 -的主动发现机制。若使用 `hikariCP` 数据源,则可以不配置 `type` 内容。 -> 若使用多数据源,或者把数据源配置到 `mybatis-flex.datasource` 下,使用 mybatis-flex 的数据源发现机制, -> 使用 druid 也可以不用配置 type,更多文档参考:[多数据源章节](./multi-datasource.md)。 +SpringBoot v3.x 添加 hikariCP 的内容如下: -**问题2:整合 Springboot 3 出现 ClassNotFoundException: NestedIOException 的错误** +```xml + + com.zaxxer + HikariCP + 5.0.1 + +``` + +## 整合 Springboot 3 出现 ClassNotFoundException: NestedIOException 的错误 需要排除 flex 中的 mybatis-spring 的依赖,主动添加最新版本的 mybatis-spring 依赖。 @@ -52,3 +58,23 @@ spring: ``` + + +## Spring 下使用 Druid 数据源无法启动 + +原因是在数据源的配置中,未添加 `type` 字段的配置: + +```yaml 3 +spring: + datasource: + type: com.alibaba.druid.pool.DruidDataSource + url: jdbc:mysql://127.0.0.1:3306/dbtest + username: root + password: 123456 +``` +第 3 行中的 `type` 字段不能为空,这个并非是 MyBaits-Flex 的问题,而是 Spring 没有内置对 Druid 数据源类型 +的主动发现机制。若使用 `hikariCP` 数据源,则可以不配置 `type` 内容。 + +> 若使用多数据源,或者把数据源配置到 `mybatis-flex.datasource` 下,使用 mybatis-flex 的数据源发现机制, +> 使用 druid 也可以不用配置 type,更多文档参考:[多数据源章节](./multi-datasource.md)。 +