spring Boot config服务器生产设置中出现错误“You need to configure a uri for git repository”,

m0rkklqb  于 2023-03-02  发布在  Spring
关注(0)|答案(1)|浏览(358)

我有一个Spring Boot Config服务器,它从本地资源文件夹读取一些属性。

  • 资源
  • 配置
  • application-production.properties
  • application.properties
  • application.properties

在参考资料/www.example.com中,我有以下内容:application.properties, I have the following:

spring.application.name=configserver
server.port=8012
spring.profiles.active=native
spring.cloud.config.server.native.search-locations=classpath:/config

这在dev中运行良好,但在生产中,在Kubernetes清单中,我传递以下代码:

env:
  - name: SPRING_PROFILES_ACTIVE
    value: "production"

我从尝试启动此程序的pod中收到以下错误:
2023 - 02 - 27 22:56:43.192信息1---[主]. c.c.配置服务器应用程序:以下1个情景模式处于活动状态:"生产" 2023 - 02 - 27 22:56:48.082信息1---[
main] o.s.云.上下文.作用域.通用作用域:网站ID = f34714c7-eae5 - 36bb-b71e-023da97acc11 2023 - 02 - 27 22:56:50.190信息1---[主要] o.s.b.w.嵌入式.Tomcat初始化的端口:8080(http)2023 - 02 - 27 22:56:50.205信息1---[主] o.Apache. catalina.核心.标准服务
:正在启动服务[Tomcat] 2023 - 02 - 27 22:56:50.205信息1---[
main]组织. Apache. catalina.核心.标准引擎:正在启动Servlet引擎:[ApacheTomcat浏览器/1999] 2023年02月27日22:56:50.781浏览次数:100次
主目录] o.a.c.c.C. [Tomcat].[本地主机].[/]:正在初始化Spring嵌入式Web应用上下文2023 - 02 - 27 22:56:50.781信息1---[
main] w.s.c.服务器网络服务器应用程序上下文:根Web应用程序上下文:初始化在7294毫秒内完成2023 - 02 - 27 22:56:57.701警告1---[main]配置服务器网络服务器应用程序上下文:上下文初始化期间遇到异常-取消刷新尝试:org.springframework.beans.factory.BeanCreationException:创建在类路径资源[org/springframework/cloud/config/server/config/DefaultRepositoryConfiguration.class]中定义的名为"默认环境存储库"的Bean时出错:调用init方法失败;嵌套异常是java. lang.非法状态异常:您需要为git仓库配置一个URI。2023 - 02 - 27 22:56:57.704信息1---[main] o. apache. catalina. core.标准服务:正在停止服务[Tomcat] 2023 - 02 - 27 22:56:57.796信息1---[主]条件评估报告日志记录侦听器:
启动ApplicationContext时出错。要显示条件报告,请在启用"调试"的情况下重新运行应用程序。2023 - 02 - 27 22:56:57.993错误1---[main] o.s.b.d. LoggingFailureAnalysisReporter

***************************应用程序启动失败

描述:
无效的配置服务器配置。
行动:
如果你使用的是git配置文件,你需要在配置文件中设置一个Git URI;如果你设置了spring. cloud. config. server. bootstrap = true,你需要使用复合配置文件。
我对SpringBoot中的配置文件了解不够,但是我如何在Production中运行配置服务器并为路径指定native?

luaexgnf

luaexgnf1#

问题是SPRING_PROFILES_ACTIVE环境变量覆盖了application.properties中指定的spring.profiles.active,从而使native不活动。
您应该将spring.profiles.active替换为spring.profiles.include
有时候,拥有添加到活动配置文件而不是替换它们的属性是有用的。spring.profiles.include属性可用于在spring.profiles.active属性激活的配置文件之上添加活动配置文件。
spring.profiles.active类似,spring.profiles.include只能用于非配置文件特定的文档。
供参考:Spring文档-添加活动配置文件

相关问题