我们鼓励使用英文,如果不能直接使用,可以使用翻译软件,您仍旧可以保留中文原文。
We recommend using English. If you are non-native English speaker, you can use the translation software.
- I have searched the [issues]of this repository and believe that this is not a duplicate.
- I have checked the [FAQ]of this repository and believe that this is not a duplicate.
Which Component
Nacos Discovery 1.4.1
dubbo
Spring Cloud Alibaba 2.2.2 & 2.2.4 & 2.2.5
Describe the bug
I follow the official demo, only different with more maven modules.
Nacos cannot find serviceName
and start failing, with setting spring.application.name
.
After setting spring.cloud.nacos.discovery.service
, it run well.
debug info:
In the NacosDiscoveryProperties.java
code, the service
field is incorrectly set(null).
I guess the high probability of the bug is caused by the startup sequence of Nacos.
ERROR:namingService subscribe failed
java.lang.IllegalArgumentException: Param 'serviceName' is illegal, serviceName is blank
To Reproduce
project structure in maven pom.xml
<modules>
//for run
<module>zeus-rpc-provider</module>
<module>zeus-rpc-api</module>
<module>zeus-rpc-dao</module>
<module>zeus-rpc-manager</module>
<module>zeus-rpc-service</module>
<module>zeus-rpc-web</module>
<module>zeus-rpc-consumer-demo</module>
</modules>
application.properties
# 应用名称
spring.application.name=zeus-rpc
# dubbo 协议
dubbo.protocol.id=dubbo
dubbo.protocol.name=dubbo
# Dubbo 消费端订阅服务端的应用名,多个服务提供者用逗号分隔
# 这里订阅"自己",会被忽略掉,请根据实际情况添加
dubbo.cloud.subscribed-services=zeus-rpc
# dubbo 服务扫描基准包
dubbo.scan.base-packages=com.now.zeus.zeusrpc
# Nacos帮助文档: https://nacos.io/zh-cn/docs/concepts.html
# Nacos认证信息
spring.cloud.nacos.discovery.username=nacos
spring.cloud.nacos.discovery.password=nacos
# Nacos 服务发现与注册配置,其中子属性 server-addr 指定 Nacos 服务器主机和端口
spring.cloud.nacos.discovery.server-addr=dnacos.nowco.com:80
# 注册到 nacos 的指定 namespace,默认为 public。取值范围:local,dev,pre,online
spring.cloud.nacos.discovery.namespace=xxxx-3dbb-4437-xxx-66696b1local'
# 这里必须要指定service的名称。跟spring.application.name一致; 这里注解掉就会报错
# spring.cloud.nacos.discovery.service=${spring.application.name}
# dubbo.config-center.namespace=local
# dubbo.registry.parameters.namespace=local
logging.config=classpath:log4j2-local.xml
# web port
server.port=28080
# dubbo 协议端口( -1 表示自增端口,从 20880 开始)
dubbo.protocol.port=21880
error detail:
[2021-03-12 11:20:46.157]ERROR:namingService subscribe failed, properties:NacosDiscoveryProperties{serverAddr='dnacos.now.com:80', endpoint='', namespace='xxxx-3dbb-4437-xxx-66696b1local', watchDelay=30000, logName='', service='', weight=1.0, clusterName='DEFAULT', group='DEFAULT_GROUP', namingLoadCacheAtStart='false', metadata={preserved.register.source=SPRING_CLOUD}, registerEnabled=true, ip='192.168.4.xxx', networkInterface='', port=-1, secure=false, accessKey='', secretKey='', heartBeatInterval=null, heartBeatTimeout=null, ipDeleteTimeout=null}
[2021-03-12 11:20:46.157]==>com.alibaba.cloud.nacos.discovery.NacosWatch.start(NacosWatch.java:127)[main]
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.1.jar!/:?]
at com.alibaba.nacos.client.naming.NacosNamingService.subscribe(NacosNamingService.java:457) ~[nacos-client-1.4.1.jar!/:?]
at com.alibaba.cloud.nacos.discovery.NacosWatch.start(NacosWatch.java:123) [spring-cloud-starter-alibaba-nacos-discovery-2.2.5.RELEASE.jar!/:2.2.5.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:182) [spring-context-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:53) [spring-context-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:360) [spring-context-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:158) [spring-context-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:122) [spring-context-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:895) [spring-context-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:554) [spring-context-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) [spring-boot-2.3.7.RELEASE.jar!/:2.3.7.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.7.RELEASE.jar!/:2.3.7.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.7.RELEASE.jar!/:2.3.7.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405) [spring-boot-2.3.7.RELEASE.jar!/:2.3.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.7.RELEASE.jar!/:2.3.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.7.RELEASE.jar!/:2.3.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.7.RELEASE.jar!/:2.3.7.RELEASE]
at com.nowxxxx.zeus.zeusrpc.ZeusRpcApplication.main(ZeusRpcApplication.java:12) [classes!/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_112]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_112]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_112]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_112]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) [zeus-rpc-provider.jar:?]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:107) [zeus-rpc-provider.jar:?]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) [zeus-rpc-provider.jar:?]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) [zeus-rpc-provider.jar:?]
Expected behavior
Nacos will automatically configure spring.cloud.nacos.discovery.service
from spring.application.name
Screenshots
Additional context
MacOS 、Java8
5条答案
按热度按时间ffdz8vbo1#
在spring cloud 下边 需要注意配置文件的加载顺序
bootstrap.properties > application.properties > application-dev(prod).properties
你可以把application.properties改名为bootstrap.properties再尝试一下
atmip9wb2#
我的配置放在 bootstrap.properties 里会报类似的异常
我的环境是:
spring-boot-starter-parent:2.4.2
spring-cloud-dependencies:2020.0.0
spring-cloud-alibaba-dependencies:2021.1
lbsnaicq3#
我的配置放在 bootstrap.properties 里会报类似的异常
我的环境是: spring-boot-starter-parent:2.4.2 spring-cloud-dependencies:2020.0.0 spring-cloud-alibaba-dependencies:2021.1
@mj19910923 你当前环境的版本,延用老版本加载方式(
bootstrap.properties
) 需要增加以下依赖wljmcqd84#
我的配置放在 bootstrap.properties 里会报类似的异常
我的环境是: spring-boot-starter-parent:2.4.2 spring-cloud-dependencies:2020.0.0 spring-cloud-alibaba-dependencies:2021.1
@mj19910923 你当前环境的版本,延用老版本加载方式(
bootstrap.properties
) 需要增加以下依赖加上此依赖问题还是存在, 复现demo链接
jum4pzuy5#
我的配置放在 bootstrap.properties 里会报类似的异常
我的环境是: spring-boot-starter-parent:2.4.2 spring-cloud-dependencies:2020.0.0 spring-cloud-alibaba-dependencies:2021.1
@mj19910923 你当前环境的版本,延用老版本加载方式(
bootstrap.properties
) 需要增加以下依赖加上此依赖问题还是存在, 复现demo链接
问题已解决,感谢大佬🙇🏼🙇🏼🙇🏼