Home > database >  Spring config server cannot be disabled for local development
Spring config server cannot be disabled for local development

Time:10-11

I was updating microservice to the newest Springboot - for now it is 2.5.5 with cloud version 2020.0.4. However there were some changes related to connection with config server. Previously config server configuration looked like this:

spring:
  cloud:
    config:
      uri: ${CONFIG_SERVER_URI:http://localhost:8888}
      fail-fast: ${CONFIG_FAIL_FAST:true}

However now it's required to provide it this way:

spring:
  config:
    import: configserver:${CONFIG_SERVER_URI:http://localhost:8888}

And that would be perfectly fine, except I am not able to run microservice locally without connecting to config server. Previously I did it like this:

spring:
  cloud:
    config:
      enabled: false

And it was perfectly fine, I had separate application-local.yaml file and had what I wanted. Now I tried this (according to what is said in documentation):

spring:
  cloud:
    config:
      import-check:
        enabled: false
      enabled: false
  config:
    import: "optional:configserver:http://localhost:8888"

But once I run microservice locally, I get only single log like this: Connected to the target VM, address: '127.0.0.1:59759', transport: 'socket' And basically nothing more, seems like it keeps trying to connect to config server, because if I run config server and after this try to run my microservice, it's working fine. Additional weird thing is that IntelliJ is showing me that it doesn't recognize this import-check property. As for dependencies I have only implementation 'org.springframework.cloud:spring-cloud-starter-config:3.0.5' related to config server.

Is there some way to run microservice locally so that it's not connecting to config server using Spring Boot 2.4 ? I don't want to use bootstrapping and providing additional dependency, since there is no point to use legacy stuff.

CodePudding user response:

Here is the configuration I have for application.yaml in /src/main/resources folder.

---
spring:
  config:
    activate:
      on-profile: "!config-local"
    import: configserver:http://config-server.example.com:8888/
  cloud:
    config.fail-fast: true
---
spring:
  config:
    activate:
      on-profile: "config-local"
    import: optional:configserver:http://localhost:8888/
  cloud:
    config:
      enabled: false

And in Intellij IDEA Run config, I set the active Profile as config-local this works with Springboot 2.5.5 and

ext {
    set('springCloudVersion', "2020.0.4")
}
  • Related