How to selectively disable Eureka discovery client with Spring?

zinc wombat picture zinc wombat · Feb 2, 2016 · Viewed 41.4k times · Source

Is there a way to disable spring-boot eureka client registration based on the spring profile?

Currently I use the following annotations:

@Configuration
@EnableAutoConfiguration
@EnableDiscoveryClient
@EnableConfigServer

public class ConfigApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConfigApplication.class, args);
    }
}

What I need is either a conditional such as (excuse the pseudo code)

@if (Profile!="development")
@EnableDiscoveryClient
@endif

Or some way in the application properties file. I have tried setting application.yml file as:

spring:
  profiles: development
  cloud:
    discovery:
      enabled: false

But this did not work.

Answer

dmitryvim picture dmitryvim · Jun 16, 2016

You can disable eureka client in application.yml using this:

eureka:
  client:
    enabled: false

It's also for one profile