搭建微服务模块踩得坑

本文总结了在Spring Boot和Spring Cloud项目中常见的问题及其解决方案,包括FeignClient配置错误、Mybatis mapper-locations设置、版本匹配、Maven测试错误、Spring Boot启动插件、Kotlin版本不兼容、Druid与Flyway多数据源配置、以及Spring Boot Admin与Actuator的关系。此外,还提及了在引入Flyway和Seata时遇到的问题和解决策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、坑1  api中feignclient中的名字

@FeignClient(name = "****") 和 该微服务名字不一样,调用api 会报feign.FeignException$ServiceUnavailable: [503 Service Unavailable] during GET …

解决方法: name = "user-server" 的名字要和 application.yaml中spring: application: name: user-server 一样

2、坑2  application.yaml中配置mybatis的mapper-locations,引入其他模块中的mapper.xml文件

 mapper-locations: classpath:mybatis/mappers/*.xml   不加* 会导致 Invalid bound statement (not found)
 
解决方法:  
将原来的 mapper-locations: classpath:mybatis/mappers/*.xml 替换为
mapper-locations: classpath*:mybatis/mappers/*.xml

3、 坑3 搭建微服务 springboot和springcloud的版本要对应,否则会报错

4、 坑4 执行maven install的时候 当执行到test命令时会报maven-surefire相关的错

解决方法

在pom文件加入下面这个

    <build>
        <plugins>
  
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
            </plugin>
        </plugins>
    </build>

5、坑5  执行maven install的时候会报错

spring-boot-maven-plugin

解决方法: 在启动类的pom文件中加入

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

   
        </plugins>
    </build>

其他非启动类模块的pom文件,不要加入这个

6、 坑6 启动服务,springboot启动报错Error:Kotlin: Module was compiled with an incompatible version of Kotlin. The binary...

解决方法: idea中菜单栏 Build —> Rebuild Project  即可

7、 坑7 使用druid 配置多数据源 和flyway兼容问题

 解决方法:见

Flyway配置(包含多数据源配置)及使用规范_beautyofmath的博客-优快云博客

8、坑8 配置多数据源,一定要注意各个配置项相互对应

9、spring-boot-admin-starter 和 spring-boot-starter-actuator关系 

1、都是用来监控微服务的

2、spring-boot-admin-starter 中已经集成了 spring-boot-starter-actuator

SBA 全称 Spring Boot Admin 是一个管理和监控 Spring Boot 应用程序的开源项目。分为admin-server 与 admin-client 两个组件,admin-server通过采集 actuator 端点数据,显示在 spring-boot-admin-ui 上,已知的端点几乎都有进行采集,通过 spring-boot-admin 可以动态切换日志级别、导出日志、导出heapdump、监控各项指标 等等….

Spring Boot Admin 在对单一应用服务监控的同时也提供了集群监控方案,支持通过eureka、consul、zookeeper等注册中心的方式实现多服务监控与管理…
 

10、在搭建一个微服务中,同时引入flyway和seata 相关配置和包,启动该服务会报错,io.seata.common.exception.ShouldNeverHappenException: [xid:null]get tablemeta failed

解决方法:先引入flyway相关配置将服务启动成功后,再引入seata相关配置,启动服务

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值