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

相关推荐
毕设源码-赖学姐1 小时前
【开题答辩全过程】以 高校评教评学系统的设计与实现为例,包含答辩的问题和答案
java·eclipse
老华带你飞1 小时前
博物馆展览门户|基于Java博物馆展览门户系统(源码+数据库+文档)
java·开发语言·数据库·vue.js·spring boot·后端
路边草随风2 小时前
iceberg 基于 cosn 构建 catalog
java·大数据
It's now2 小时前
Spring Framework 7.0 原生弹性功能系统讲解
java·后端·spring
点PY2 小时前
C++ 中 std::async 和 std::future 的并发性
java·开发语言·c++
为爱停留2 小时前
Spring AI实现RAG(检索增强生成)详解与实践
人工智能·深度学习·spring
一 乐2 小时前
人事管理系统|基于Springboot+vue的企业人力资源管理系统设计与实现(源码+数据库+文档)
java·前端·javascript·数据库·vue.js·spring boot·后端
带刺的坐椅2 小时前
Solon AI 开发学习19 - 结合 Solon Flow 实现 ReAct 效果
java·ai·chatgpt·llm·openai·solon·deepseek
CoderYanger2 小时前
Java SE——12.异常(≠错误)《干货笔记》
java·开发语言
Data_agent2 小时前
1688获得1688店铺所有商品API,python请求示例
java·开发语言·python