Spring Cloud 配置服务器无法使用本地属性文件

2024-04-25

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

然而,我在让它读取本地属性文件而不是从 github 中提取属性时遇到了一些问题。即使我删除了对 github 的所有引用,spring 似乎也会忽略本地文件。这里发布了一个类似的问题:Spring-Cloud 配置服务器忽略配置属性文件 https://stackoverflow.com/questions/26786865/spring-cloud-configuration-server-ignores-configuration-properties-file

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


我所有的代码都在这里https://github.com/spencergibb/communityanswers/tree/so27131143 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"
                }
          }
     ]
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Spring Cloud 配置服务器无法使用本地属性文件 的相关文章

随机推荐