gpt4 book ai didi

java - Spring Cloud Configuration Server 不使用本地属性文件

转载 作者:IT老高 更新时间:2023-10-28 13:56:00 25 4
gpt4 key购买 nike

我一直在玩 github 上的 Spring Cloud 项目:https://github.com/spring-cloud/spring-cloud-config

但是,我在让它读取本地属性文件而不是从 github 中提取属性时遇到了一些问题。即使我删除了对 github 的所有引用,spring 似乎也忽略了本地文件。这里发布了一个类似的问题:Spring-Cloud configuration server ignores configuration properties file

但我还没有看到任何好的答案。我想知道是否有人可以指出我的例子?我想在本地设置我的属性,而不是使用任何类型的 git repo。我想有人以前遇到过这种情况,如果某处有这样的例子,我真的很想看到它,这样我就可以朝着正确的方向前进。

最佳答案

我所有的代码都在这里https://github.com/spencergibb/communityanswers/tree/so27131143

src/main/java/Application.java

@Configuration
@EnableAutoConfiguration
@EnableConfigServer
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

src/main/resources/application.yml

spring:
application:
name: myconfigserver
profiles:
active: native

my:
property: myvalue

src/main/resources/myapp.yml

my:
otherprop: myotherval

要获取名为 myapp 的应用的属性,请执行以下操作。

curl http://localhost:8080/myapp/default

{
"name": "default",
"label": "master",
"propertySources": [
{
"name": "applicationConfig: [classpath:/myapp.yml]",
"source": {
"my.otherprop": "myotherval"
}
},
{
"name": "applicationConfig: [classpath:/application.yml]",
"source": {
"spring.application.name": "myconfigserver",
"spring.profiles.active": "native",
"my.property": "myvalue"
}
}
]
}

关于java - Spring Cloud Configuration Server 不使用本地属性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27131143/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com