首页 > 解决方案 > spring-boot 2.5.5 属性“spring.config.import”未定义?

问题描述

将 spring-boot:2.3.11.RELEASE 升级到 spring-boot:2.5.5 和 spring-cloud:Hoxton.SR11 到 spring-cloud:2020.0.4 后,spring-boot:run 失败并显示:

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

Description:

No spring.config.import property has been defined

Action:

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

建议很清楚,所以我补充说

spring.cloud.config.enabled=false
spring.cloud.config.import-check.enabled=false
spring.config.import=optional:configserver:

application.propertiesbootstrap.properties文件

application.properties我必须注释掉行,spring.config.import=optional:configserver:否则它会失败java.lang.IllegalStateException: Unable to load config data from 'optional:configserver:' ......... Caused by: java.lang.IllegalStateException: File extension is not known to any PropertySourceLoader

由于我不需要在bootstrap.properties中将其注释掉,因此可能会完全忽略值

然而,应用程序本身失败的方式与没有添加任何新属性的方式相同。

有什么想法有什么问题吗?spring.config.import=...的正确格式是什么?

编辑:添加依赖后

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

它不再忽略 bootstrap.properties 中的属性,因此我也不得不在此处注释掉“spring.config.import=optional:configserver:”。但是应用程序仍然失败,“没有定义 spring.config.import 属性”

标签: spring-bootspring-cloudspring-cloud-config

解决方案


在 Spring Cloud 2020 中,您不再需要 bootstrap.properties,导入 spring-cloud-starter-bootstrap仅启用传统方式来使用它。只需删除它...

您需要添加

spring.config.import=optional:configserver:http://your.config.server.com

进入您的 application.properties。但是,我不确定您要达到什么目标,因为您的

spring.cloud.config.enabled=false

更多信息


推荐阅读