草庐IT

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

coder 2023-05-12 原文

我一直在玩 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/

有关java - Spring Cloud Configuration Server 不使用本地属性文件的更多相关文章

随机推荐