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

相关推荐
Resean02231 天前
Spring 源码分析(二)配置类的解析与扫描
java·后端·spring
小毛球.1 天前
第 3 篇:IDEA 最新版下载与完整安装教程(Mac)
java·macos·intellij-idea·idea
Misnearch1 天前
ScheduledExecutorService
java·线程池
ashiho1 天前
【LeetCode hot 100】3. 无重复字符的最长子串 (三种解法)
java·数据结构·后端·算法·leetcode·滑动窗口
T_Wizard1 天前
AI 回复为什么要转圈 3 秒才「啪」一下全出来?把流式输出拆开看,顺便踩了 6 个坑
java·ai编程
CoderYanger1 天前
Java EE 进阶:9.MyBatis 操作数据库(进阶)(第二弹)
java·数据库·面试·职场和发展·java-ee·tomcat·mybatis
小满、1 天前
Java 值传递
java·java 值传递
IT枫斗者枫哥1 天前
Java 异步导出只测最终行数,为什么下载时仍会少一行?
java·后端
张紫娃1 天前
idea 如何看一个类的 .class 文件
java·ide·intellij-idea
南宫鑫2 天前
Java底层实现
java