Spring Cloud Configuration Server not working with local properties file

后端 未结 9 2168
渐次进展
渐次进展 2020-12-05 07:43

I have been playing around with the Spring Cloud project on github located here: https://github.com/spring-cloud/spring-cloud-config

However I have been running into

相关标签:
9条回答
  • 2020-12-05 08:43

    All my code is here 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
    

    To get the properties for an app named myapp, do the following.

    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"
                    }
              }
         ]
    }
    
    0 讨论(0)
  • 2020-12-05 08:43

    Using spring.profiles.active=native is that what Spring documentation seems to suggest, but I couldn't get it to work either. My application.properties file is

    server.port=8888
    spring.cloud.config.profiles=native 
    

    but the response from the URL

    http://localhost:8888/config-server/env
    

    is

    {"name":"env","label":"master","propertySources":[{"name":"https://github.com/spring-cloud-samples/config-repo/application.yml","source":{"info.url":"https://github.com/spring-cloud-samples","info.description":"Spring Cloud Samples"}}]}
    

    which indicates that native profile was ignored and the server still considering github as property source.

    A small additional problem I encountered is the config service default port. According to the Sprin Cloud Config documentation it should be 8888. If I remove server.port=8888 from my application.properties the config server starts on port 8080 which is default Spring Boot port, but not the one config server should use.

    0 讨论(0)
  • 2020-12-05 08:43

    I had the same issue on my local machine, but it works fine on my remote server.

    @Oreste's answer does work for me. So I checked the error log again, And I found

     2018-06-25 16:09:49.789  INFO 4397 --- [           main] t.p.a.s.api.user.UserServiceApplication  : The following profiles are active:  someProfileISetBefore
    

    So, the root reason for my case is I set an environment variable before, but I forget to remove it. And it overrides the application properties files config.

    Hope you guys won't make the silly mistake like me. Fixed by:

     unset spring_profiles_active 
    
    0 讨论(0)
提交回复
热议问题