mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 17:48:25 +08:00
update docs
This commit is contained in:
parent
d055572776
commit
30e2f1d44e
@ -14,6 +14,7 @@ export default defineConfig({
|
|||||||
nav: [
|
nav: [
|
||||||
{text: '首页', link: '/'},
|
{text: '首页', link: '/'},
|
||||||
{text: '帮助文档', link: '/zh/what-is-mybatisflex'},
|
{text: '帮助文档', link: '/zh/what-is-mybatisflex'},
|
||||||
|
{text: '常见问题', link: '/zh/faq'},
|
||||||
{
|
{
|
||||||
text: '周边', items: [
|
text: '周边', items: [
|
||||||
{text: '示例代码', link: 'https://gitee.com/mybatis-flex/mybatis-flex-samples'},
|
{text: '示例代码', link: 'https://gitee.com/mybatis-flex/mybatis-flex-samples'},
|
||||||
@ -37,7 +38,6 @@ export default defineConfig({
|
|||||||
{text: 'Maven 依赖', link: '/zh/maven'},
|
{text: 'Maven 依赖', link: '/zh/maven'},
|
||||||
{text: '和同类框架「功能」对比', link: '/zh/comparison'},
|
{text: '和同类框架「功能」对比', link: '/zh/comparison'},
|
||||||
{text: '和同类框架「性能」对比', link: '/zh/benchmark'},
|
{text: '和同类框架「性能」对比', link: '/zh/benchmark'},
|
||||||
{text: '和 Spring 整合 常见问题', link: '/zh/mybatis-flex-with-spring'},
|
|
||||||
{text: '支持的数据库类型', link: '/zh/support-database'},
|
{text: '支持的数据库类型', link: '/zh/support-database'},
|
||||||
{text: '使用 Mybatis 原生功能', link: '/zh/use-mybatis-native'},
|
{text: '使用 Mybatis 原生功能', link: '/zh/use-mybatis-native'},
|
||||||
{text: 'QQ 交流群', link: '/zh/qq-group'},
|
{text: 'QQ 交流群', link: '/zh/qq-group'},
|
||||||
|
|||||||
@ -1,32 +1,38 @@
|
|||||||
# Mybatis-Flex 和 Spring 整合
|
# 常见问题
|
||||||
|
|
||||||
最近,看到群里有许多用户,用 MyBatis-Flex 整合 Spring 的时候遇到了一些问题,这个文档再补充说明一下。
|
## 示例中的 AccountMapper 和 "ACCOUNT" 在哪里,报错了。
|
||||||
|
|
||||||
在开始使用 Mybatis-Flex 之前,可以先看一下 MyBatis-Flex-Samples 示例,网址为:
|
Mybatis-Flex 使用了 APT 技术,这两个类是自动生成的。
|
||||||
[https://gitee.com/mybatis-flex/mybatis-flex-samples](https://gitee.com/mybatis-flex/mybatis-flex-samples)。
|
参考:[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
|
SpringBoot v2.x 添加 hikariCP 的内容如下:
|
||||||
spring:
|
|
||||||
datasource:
|
```xml
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
<dependency>
|
||||||
url: jdbc:mysql://127.0.0.1:3306/dbtest
|
<groupId>com.zaxxer</groupId>
|
||||||
username: root
|
<artifactId>HikariCP</artifactId>
|
||||||
password: 123456
|
<version>4.0.3</version>
|
||||||
|
</dependency>
|
||||||
```
|
```
|
||||||
第 3 行中的 `type` 字段不能为空,这个并非是 MyBaits-Flex 的问题,而是 Spring 没有内置对 Druid 数据源类型
|
|
||||||
的主动发现机制。若使用 `hikariCP` 数据源,则可以不配置 `type` 内容。
|
|
||||||
|
|
||||||
> 若使用多数据源,或者把数据源配置到 `mybatis-flex.datasource` 下,使用 mybatis-flex 的数据源发现机制,
|
SpringBoot v3.x 添加 hikariCP 的内容如下:
|
||||||
> 使用 druid 也可以不用配置 type,更多文档参考:[多数据源章节](./multi-datasource.md)。
|
|
||||||
|
|
||||||
**问题2:整合 Springboot 3 出现 ClassNotFoundException: NestedIOException 的错误**
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zaxxer</groupId>
|
||||||
|
<artifactId>HikariCP</artifactId>
|
||||||
|
<version>5.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
|
||||||
|
## 整合 Springboot 3 出现 ClassNotFoundException: NestedIOException 的错误
|
||||||
|
|
||||||
需要排除 flex 中的 mybatis-spring 的依赖,主动添加最新版本的 mybatis-spring 依赖。
|
需要排除 flex 中的 mybatis-spring 的依赖,主动添加最新版本的 mybatis-spring 依赖。
|
||||||
|
|
||||||
@ -52,3 +58,23 @@ spring:
|
|||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## 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)。
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user