• 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/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E

    报错内容

    java.lang.IllegalArgumentException: Param 'serviceName' is illegal, serviceName is blank
    
    • 1

    配置文件中配置的端口号为 88但是实际启动端口为8080!!!
    在这里插入图片描述

    问题分析

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

    • 2.4之前版本 spring.cloud.bootstrap.enabled = true
    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);
                }
            }
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 2.4之后版本 spring.cloud.bootstrap.enabled = false
    public static boolean bootstrapEnabled(Environment environment) {
            return (Boolean)environment.getProperty("spring.cloud.bootstrap.enabled", Boolean.class, false) || MARKER_CLASS_EXISTS;
        }
    
    • 1
    • 2
    • 3

    解决办法

    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版本!!!

    <!--SpringBoot2.4.x之后默认不加载bootstrap.yml文件,需要在pom里加上依赖-->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-bootstrap</artifactId>
         <version>3.1.3</version>
    </dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    参考

    https://developer.aliyun.com/article/937388
    SpringCloudAlibaba踩坑日记(一)nacos报错: Param ‘serviceName‘ is illegal, serviceName is blank

  • 相关阅读:
    I2C调试问题经验总结
    K8S原理架构与实战教程
    大数据培训课程Reduce Join案例实操
    【正点原子STM32连载】第五十章 照相机实验 摘自【正点原子】MiniPro STM32H750 开发指南_V1.1
    Js逆向教程-15滑块流程 极验
    PHP接口自动化测试框架实现
    unity的ui怎么显示在鼠标点击位置
    概率论得学习整理--番外3:二项式定理和 二项式系数
    Oracle之SQL plus的一些经验心得
    Windows Docs
  • 原文地址:https://blog.csdn.net/qq_41398619/article/details/133121332