Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not use active profiles to set the nacos config in bootstrap after upgrading 2023.0.3.2 #3925

Open
lwQin opened this issue Dec 13, 2024 · 2 comments
Labels
area/nacos spring cloud alibaba nacos

Comments

@lwQin
Copy link

lwQin commented Dec 13, 2024

升级到 2023.0.3.2 之后无法使用 active profiles 来设置 bootstrap 中的 nacos 配置
Could not use active profiles to set nacos config in bootstrap after upgrading 2023.0.3.2

Which Component
Nacos Config

Configuration in bootstrap-dev.properties

nacos.username=nacos
nacos.password=nacos
nacos.server=localhost:8848
nacos.namespace=xxxxx
nacos.dubbo.namespace=xxxxx

Configuration in bootstrap.properties

nacos.username=
nacos.password=
nacos.server=
nacos.namespace=
nacos.dubbo.namespace=
spring.cloud.nacos.server-addr=${nacos.server}
spring.cloud.nacos.username=${nacos.username}
spring.cloud.nacos.password=${nacos.password}
spring.cloud.nacos.config.namespace=${nacos.namespace}
spring.cloud.nacos.discovery.namespace=${nacos.namespace}
spring.config.import[0]=nacos:common.properties

To Reproduce
Steps to reproduce the behavior:

  1. 使用 IDEA 设置激活的配置文件为 dev Use IDEA set the active profiles value dev
    image
  2. 启动程序 Startup
  3. 报错 See error
***************************
APPLICATION FAILED TO START
***************************

Description:

Config data resource 'NacosConfigDataResource{properties=NacosConfigProperties{serverAddr='', encode='null', group='DEFAULT_GROUP', prefix='null', fileExtension='properties', timeout=3000, maxRetry='null', configLongPollTimeout='null', configRetryTime='null', enableRemoteSyncConfig=false, endpoint='null', namespace='', accessKey='null', secretKey='null', ramRoleName='null', contextPath='null', clusterName='null', name='null'', shares=null, extensions=null, refreshEnabled=true}, optional=false, profiles=[Profiles@5cbb84b1 active = '[dev]', default = '[default]', accepted = '[dev]'], config=NacosItemConfig{group='DEFAULT_GROUP', dataId='common.properties', suffix='properties', refreshEnabled=true, preference=null}}' via location 'nacos:common.properties' does not exist

Action:

Check that the value 'nacos:common.properties' at class path resource [bootstrap.properties] - 24:25 is correct, or prefix it with 'optional:'

2024-12-13 17:35:21.535  WARN   [       Thread-9] c.a.nacos.common.notify.NotifyCenter     : [NotifyCenter] Start destroying Publisher
2024-12-13 17:35:21.535  WARN   [       Thread-2] c.a.n.c.executor.ThreadPoolManager       : [ThreadPoolManager] Start destroying ThreadPool
2024-12-13 17:35:21.535  WARN   [       Thread-7] c.a.n.c.http.HttpClientBeanHolder        : [HttpClientBeanHolder] Start destroying common HttpClient
2024-12-13 17:35:21.535  WARN   [       Thread-9] c.a.nacos.common.notify.NotifyCenter     : [NotifyCenter] Destruction of the end
2024-12-13 17:35:21.535  WARN   [       Thread-2] c.a.n.c.executor.ThreadPoolManager       : [ThreadPoolManager] Destruction of the end
2024-12-13 17:35:21.535  WARN   [       Thread-7] c.a.n.c.http.HttpClientBeanHolder        : [HttpClientBeanHolder] Destruction of the end
  1. 直接将 nacos 的配置写在 bootstrap.properties 中则正常 It is normal to write the nacos configuration directly in bootstrap.properties
2024-12-13 17:37:53.871  INFO 35144 [kground-preinit] o.h.validator.internal.util.Version      : HV000001: Hibernate Validator 8.0.1.Final


 :: Dubbo (v3.3.2) : https://github.com/apache/dubbo
 :: Discuss group : dev@dubbo.apache.org
2024-12-13 17:37:53.968  INFO 35144 [           main] c.a.c.n.c.NacosConfigDataLoader          : [Nacos Config] Load config[dataId=common.properties, group=DEFAULT_GROUP] success

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.4.0)

2024-12-13 17:37:54.192  INFO 35144 [           main] com.xhuo.platform.web.Startup            : The following 1 profile is active: "dev"
2024-12-13 17:37:54.209  INFO 35144 [           main] c.a.c.n.c.NacosConfigDataLoader          : [Nacos Config] Load config[dataId=common.properties, group=DEFAULT_GROUP] success
@yuluo-yx
Copy link
Collaborator

社区有相关的 issu 描述,自己找找看

@yuluo-yx yuluo-yx added the area/nacos spring cloud alibaba nacos label Dec 21, 2024
@lwQin
Copy link
Author

lwQin commented Dec 23, 2024

这个问题应该是在bootstrap.properties 中使用 spring.config.import 拉取配置的顺序优先于加载环境 bootstrap-${profile}.properties 中的配置。

将 nacos 的配置信息在 bootstrap.properties 中使用占位符配置,再在 bootstrap-${profile}.properties 使用真实配置会导致spring.config.import 拉取配置时使用错误的 nacos 配置导致拉取失败

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/nacos spring cloud alibaba nacos
Projects
None yet
Development

No branches or pull requests

2 participants