Param ‘serviceName‘ is illegal, serviceName is blank,SpringCloudAlibaba踩坑记录

目录

0 前言

Param 'serviceName' is illegal, serviceName is blank,SpringCloudAlibaba

重新梳理一下nacos和gateway的配置流程,把之前配置好pom文件重新梳理一下,发现gateway服务报错了。

当前环境配置


官方推荐配置

地址链接,具体配置看官网文档

https://github.com/alibaba/spring-cloud-alibaba/wiki/版本说明

报错内容

sql 复制代码
java.lang.IllegalArgumentException: Param 'serviceName' is illegal, serviceName is blank

配置文件中配置的端口号为 88但是实际启动端口为8080!!!

问题分析

后来对比源码是SpringBoot2.4之后不会默认加载bootstrap.yaml

  • 2.4之前版本 spring.cloud.bootstrap.enabled = true
java 复制代码
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
        ConfigurableEnvironment environment = event.getEnvironment();
        if ((Boolean)environment.getProperty("spring.cloud.bootstrap.enabled", Boolean.class, true)) {
            if (!environment.getPropertySources().contains("bootstrap")) {
                ConfigurableApplicationContext context = null;
                String configName = environment.resolvePlaceholders("${spring.cloud.bootstrap.name:bootstrap}");
                Iterator var5 = event.getSpringApplication().getInitializers().iterator();

                while(var5.hasNext()) {
                    ApplicationContextInitializer<?> initializer = (ApplicationContextInitializer)var5.next();
                    if (initializer instanceof ParentContextApplicationContextInitializer) {
                        context = this.findBootstrapContext((ParentContextApplicationContextInitializer)initializer, configName);
                    }
                }

                if (context == null) {
                    context = this.bootstrapServiceContext(environment, event.getSpringApplication(), configName);
                    event.getSpringApplication().addListeners(new ApplicationListener[]{new BootstrapApplicationListener.CloseContextOnFailureApplicationListener(context)});
                }

                this.apply(context, event.getSpringApplication(), environment);
            }
        }
    }
  • 2.4之后版本 spring.cloud.bootstrap.enabled = false
java 复制代码
public static boolean bootstrapEnabled(Environment environment) {
        return (Boolean)environment.getProperty("spring.cloud.bootstrap.enabled", Boolean.class, false) || MARKER_CLASS_EXISTS;
    }

解决办法

1 配置程序参数

配置方法可以参考这个两个链接,不同IDEA版本配置方法不一样

https://blog.csdn.net/qq_42164368/article/details/108073538 IDEA参数配置方法

https://blog.csdn.net/weixin_43423377/article/details/118222124 2021新版idea为java程序添加启动参数

spring.cloud.bootstrap.enabled=true

2 增加POM文件配置

根据自己的版本指定version,查看文档看对应的spring boot版本!!!

sql 复制代码
<!--SpringBoot2.4.x之后默认不加载bootstrap.yml文件,需要在pom里加上依赖-->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
     <version>3.1.3</version>
</dependency>

参考

https://developer.aliyun.com/article/937388

SpringCloudAlibaba踩坑日记(一)nacos报错: Param 'serviceName' is illegal, serviceName is blank

相关推荐
阿维的博客日记15 分钟前
Nacos 为什么能让配置动态生效?(涉及 @RefreshScope 注解)
java·spring
雨辰AI15 分钟前
SpringBoot3 + 人大金仓读写分离 + 分库分表 + 集群高可用 全栈实战
java·数据库·mysql·政务
辰海Coding2 小时前
MiniSpring框架学习-完成的 IoC 容器
java·spring boot·学习·架构
小小编程路2 小时前
C++ 多线程与并发
java·jvm·c++
AI视觉网奇2 小时前
linux 检索库 判断库是否支持
java·linux·服务器
她的男孩2 小时前
从零搭一个企业后台,为什么我把能力拆成 Starter 和 Plugin
java·后端·架构
RainCity2 小时前
Java Swing 自定义组件库分享(七)
java·笔记·后端
Sam_Deep_Thinking2 小时前
连锁门店的外卖订单平台对接
java·微服务·架构·系统架构
_遥远的救世主_3 小时前
从一次结果集密集型查询 OOM 看 Java 服务的稳定性架构治理
java·后端
一楼的猫3 小时前
从工具链视角对比:番茄作家助手 vs 第三方写作辅助方案
java·服务器·开发语言·前端·学习·chatgpt·ai写作