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

相关推荐
曹牧33 分钟前
Spring Boot:如何测试Java Controller中的POST请求?
java·开发语言
爬山算法1 小时前
Hibernate(90)如何在故障注入测试中使用Hibernate?
java·后端·hibernate
kfyty7252 小时前
集成 spring-ai 2.x 实践中遇到的一些问题及解决方案
java·人工智能·spring-ai
猫头虎2 小时前
如何排查并解决项目启动时报错Error encountered while processing: java.io.IOException: closed 的问题
java·开发语言·jvm·spring boot·python·开源·maven
李少兄2 小时前
在 IntelliJ IDEA 中修改 Git 远程仓库地址
java·git·intellij-idea
忆~遂愿2 小时前
ops-cv 算子库深度解析:面向视觉任务的硬件优化与数据布局(NCHW/NHWC)策略
java·大数据·linux·人工智能
小韩学长yyds2 小时前
Java序列化避坑指南:明确这4种场景,再也不盲目实现Serializable
java·序列化
仟濹2 小时前
【Java基础】多态 | 打卡day2
java·开发语言
Re.不晚2 小时前
JAVA进阶之路——无奖问答挑战2
java·开发语言
Ro Jace3 小时前
计算机专业基础教材
java·开发语言