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

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

前言

这俩天闲来无事想搭建一套最新版本的微服务,顺便写博客记录一下,我用的是当前时间(2022-04-14)最新版本

在这里插入图片描述
在这里插入图片描述

报错内容

java.lang.IllegalArgumentException: Param 'serviceName' is illegal, serviceName is blank
    at com.alibaba.nacos.api.naming.utils.NamingUtils.getGroupedName(NamingUtils.java:47) ~[nacos-api-1.4.2.jar:na]
后来对比源码是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);
            }
        }
    }
  • 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 配置程序参数

spring.cloud.bootstrap.enabled=true 

在这里插入图片描述

解决方案2 添加bootstrap依赖

<!--SpringBoot2.4.x之后默认不加载bootstrap.yml文件,需要在pom里加上依赖-->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
相关文章
|
SpringCloudAlibaba 安全 Java
SpringCloud版本升级后bootstrap.yml配置不生效
SpringCloud版本升级后bootstrap.yml配置不生效
3049 1
|
消息中间件 JSON Java
Spring Boot、Spring Cloud与Spring Cloud Alibaba版本对应关系
Spring Boot、Spring Cloud与Spring Cloud Alibaba版本对应关系
36570 1
|
负载均衡 网络协议 Java
spring-cloud-loadbalancer 将替换 ribbon
Spring官方推出新型负载均衡利器“spring-cloud-loadbalancer”,将代替Ribbon。
|
Java Nacos Spring
Spring Cloud Alibaba中,shared-configs、extension-configs 读不到配置怎么办?
Spring Cloud Alibaba中,shared-configs、extension-configs 读不到配置怎么办?【1月更文挑战第25天】【1月更文挑战第121篇】
1572 1
|
Java 数据库连接 Spring
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could
这个错误通常出现在使用Spring Boot进行数据库连接时。错误信息表明Spring Boot未能配置一个DataSource,因为没有指定'url'属性,并且没有发现默认的数据库连接。
6321 0
|
SpringCloudAlibaba 负载均衡 Java
【一】SpringCloud Alibaba之Nacos整合篇(作为注册中心)
【一】SpringCloud Alibaba之Nacos整合篇(作为注册中心)
1191 1
【一】SpringCloud Alibaba之Nacos整合篇(作为注册中心)
【超详细】springboot + springdoc-openapi + knife4j 集成案例
springdoc-openapijava库有助于使用 spring boot 项目自动生成 API 文档。 springdoc-openapi通过在运行时检查应用程序以根据 spring 配置、类结构和各种注释推断 API 语义来工作。
|
SpringCloudAlibaba 负载均衡 前端开发
【十】SpringCloud Alibaba之整合gateway(包括配置详解以及各种坑)
【十】SpringCloud Alibaba之整合gateway(包括配置详解以及各种坑)
1290 2
|
Cloud Native Java Nacos
springcloud/springboot集成NACOS 做注册和配置中心以及nacos源码分析
通过本文,我们详细介绍了如何在 Spring Cloud 和 Spring Boot 中集成 Nacos 进行服务注册和配置管理,并对 Nacos 的源码进行了初步分析。Nacos 作为一个强大的服务注册和配置管理平台,为微服务架构提供
5102 14
|
Java 数据库连接 mybatis
mybatis返回结果为List<Map<String, Object>>的写法
mybatis返回结果为List<Map<String, Object>>的写法
2323 1

热门文章

最新文章