踩坑过程
因为项目采用 Dubbo 微服务架构,所以每个服务都会有一个 API 模块和 Service 模块,在 API 模块中只是定义一些对外公开的接口和传输对象。由于项目使用了 Pagehelper,因此需要引入pagehelper-spring-boot-starter依赖,结果在网关中引入每个服务的 API 模块后,发现启动时报错,提示需要配置 MySQL 连接。
解决方法
在 API 中引入pagehelper-spring-boot-starter依赖时排除mybatis-spring-boot-starter依赖即可。代码如下:
<!-- 分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>