当使用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加载配置文件,或者从命令行参数、环境变量等加载配置信息。