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

标签 java spring spring-cloud

我一直在玩 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 - 上一页 URL JSF

java - Spring数据存储库在测试用例类中未使用@Mock注入(inject)返回null?

java - 为什么我们要检查是否启用了调试或日志错误?

Spring Cloud : Eureka Client registration/deregistration cycle

java - 为 Feign 客户端添加 OkHttp 自定义拦截器

java - 没有名字的静态方法

java - hibernate 模式 : maven dependency version information

java - 如何在java中存储php登录 session 如何发送 session

java - spring boot中创建KafkaTemplate的正确方法

spring - Spring Cloud AWS如何从缓存集群的逻辑名称获取配置端点?