alibaba/spring-cloud-alibaba

连接 Nacos 2.4.2 启动项目提示 java.lang.IllegalArgumentException: illegal URI: xxx

Closed this issue · 0 comments

项目使用版本

spring-boot.version:2.7.18
spring-cloud.version::2021.0.9
spring-cloud-alibaba.version:2021.0.6.0
nacos.version:2.4.2

SpringBoot 配置文件

spring:
  application:
    name: @artifactId@
  cloud:
    nacos:
      username: ${NACOS_USER:top_mbc}
      password: ${NACOS_PWD:top_mbc}
      discovery:
        server-addr: 192.168.12.137:8848
        namespace: ${NACOS_NAMESPACE}
        metadata:
          VERSION: ${PROJECT_VERSION:'DEV_LOCAL'}
      config:
        server-addr: ${spring.cloud.nacos.discovery.server-addr}
        namespace: ${spring.cloud.nacos.discovery.namespace}
  config:
    import:
      - optional:nacos:application-@profiles.active@.yml
      - optional:nacos:${spring.application.name}-@profiles.active@.yml

开发环境下能正确启动项目,但是在 docker 部署后的项目启动提示 java.lang.IllegalArgumentException: illegal URI: 地址不对?(查看日志将发现其中的 “ http://192.168.12.137:8848/application-prod.yml” 这个地址在追加配置文件名称的时候被添加了一个换行符号?)

错误日志

08:32:06.838 [main] ERROR org.springframework.boot.SpringApplication - Application run failed java.lang.IllegalArgumentException: illegal URI: http://192.168.12.137:8848 /application-prod.yml at com.alibaba.cloud.nacos.configdata.NacosConfigDataLocationResolver.getUri(NacosConfigDataLocationResolver.java:208) at com.alibaba.cloud.nacos.configdata.NacosConfigDataLocationResolver.getUri(NacosConfigDataLocationResolver.java:188) at com.alibaba.cloud.nacos.configdata.NacosConfigDataLocationResolver.loadConfigDataResources(NacosConfigDataLocationResolver.java:158) at com.alibaba.cloud.nacos.configdata.NacosConfigDataLocationResolver.resolveProfileSpecific(NacosConfigDataLocationResolver.java:151) at org.springframework.boot.context.config.ConfigDataLocationResolvers.lambda$resolve$2(ConfigDataLocationResolvers.java:120) at org.springframework.boot.context.config.ConfigDataLocationResolvers.resolve(ConfigDataLocationResolvers.java:126) at org.springframework.boot.context.config.ConfigDataLocationResolvers.resolve(ConfigDataLocationResolvers.java:119) at org.springframework.boot.context.config.ConfigDataLocationResolvers.resolve(ConfigDataLocationResolvers.java:107) at org.springframework.boot.context.config.ConfigDataImporter.resolve(ConfigDataImporter.java:106) at org.springframework.boot.context.config.ConfigDataImporter.resolve(ConfigDataImporter.java:98) at org.springframework.boot.context.config.ConfigDataImporter.resolveAndLoad(ConfigDataImporter.java:86) at org.springframework.boot.context.config.ConfigDataEnvironmentContributors.withProcessedImports(ConfigDataEnvironmentContributors.java:116) at org.springframework.boot.context.config.ConfigDataEnvironment.processWithProfiles(ConfigDataEnvironment.java:311) at org.springframework.boot.context.config.ConfigDataEnvironment.processAndApply(ConfigDataEnvironment.java:232) at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:102) at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:94) at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:102) at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:87) at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:178) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:171) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:145) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:133) at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:85) at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:66) at java.util.ArrayList.forEach(ArrayList.java:1259) at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:120) at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:114) at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:65) at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:344) at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1289) at com.top.mbc.oms.CloudOmsApplication.main(CloudOmsApplication.java:23) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)