首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >未定义spring.config.import属性

未定义spring.config.import属性
EN

Stack Overflow用户
提问于 2021-05-12 16:23:28
回答 16查看 135.5K关注 0票数 89

创建应用程序时出错。在这方面有什么帮助吗?

代码语言:javascript
运行
复制
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.
EN

回答 16

Stack Overflow用户

回答已采纳

发布于 2021-05-12 17:31:40

Maven的解决方案

pom.xml文件中添加以下依赖项:

代码语言:javascript
运行
复制
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

Gradle的解决方案

添加build.gradle文件:

代码语言:javascript
运行
复制
implementation('org.springframework.cloud:spring-cloud-starter-bootstrap')

解决了我的问题。

票数 154
EN

Stack Overflow用户

发布于 2022-01-22 12:51:59

因为您使用了Spring和Spring 的新版本,但是您正在尝试用旧的方式配置它。

原因

客户机已经更改,从技术上讲,bootstrap.propertiesbootstrap.yml 文件已不再推荐使用。

正确解

  1. 将所有属性从boostrap.properties移动到application.properties (也可以是.yml )
  2. 删除bootstrap.properties文件
  3. spring.cloud.config.uri=http://localhost:8888替换为spring.config.import=configserver:http://localhost:8888

这是告诉您Spring应用程序希望从运行在上的Spring服务加载属性的正确方法。

遗留解决方案

如果要使用遗留的bootstrap.properties文件,只需添加以下依赖项:

代码语言:javascript
运行
复制
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

请注意,这是一个不推荐的机制__,所以如果您要创建一个新项目,将继续使用正确的解决方案__。

票数 68
EN

Stack Overflow用户

发布于 2021-08-05 14:27:26

根本原因是SpringBoot2.4更改了它的默认功能。一个新的spring.config.import属性是强制性的。

若要修复,请添加新的spring.config.import属性。下面是一个在application.yml中对我起作用的例子。

代码语言:javascript
运行
复制
spring:
  config:
    import: "optional:configserver:"

当您需要设置不同的值时,这里是文档:

Spring Boot Config数据导入 SpringBoot2.4引入了一种通过spring.config.import属性导入配置数据的新方法。现在,这是绑定到Config Server的默认方法。

票数 40
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67507452

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档