No spring.config.import property has been defined

当使用springCloud2025 , nacos开发时,由于项目中使用了bootstrap.yml, 直接报上面的错。

详细报错如下:


***************************
APPLICATION FAILED TO START
***************************

Description:

No spring.config.import property has been defined

Action:

Add a spring.config.import=nacos: property to your configuration.
    If configuration is not required add spring.config.import=optional:nacos: instead.
    To disable this check, set spring.cloud.nacos.config.import-check.enabled=false.


Process finished with exit code 1

原因是由于没有添加下面的依赖:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

解决方法1:

添加上面的bootstrap 依赖。

解决方法2:

去掉bootstrap.yml, 直接使用application.yml 也可以,这样也避免引入了多余的依赖。

原来在:在 Spring Cloud 2020.0.2 及之后的版本中,bootstrap.properties 的相关依赖被移除,需要手动添加 spring-cloud-starter-bootstrap

关于bootstrap:

Spring Cloud Starter Bootstrap 是Spring Cloud项目中的一个关键组件,它主要负责在Spring Boot应用程序启动时加载Bootstrap Context。这个Bootstrap Context是一个独立的Spring应用上下文,与应用的主Context不同,它主要用于加载应用程序的外部配置信息。

Bootstrap Context的加载过程

当Spring Boot应用程序启动时,Bootstrap Context会优先于应用的主Context被加载。这是为了确保应用程序的配置信息能够在启动过程中被正确加载。例如,它可以从Config Server加载配置文件,或者从命令行参数、环境变量等加载配置信息。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

nextera-void

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值