Spring
Eureka
Discovery Client
Microservices
Application Configuration

How to selectively disable Eureka discovery client with Spring?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

In Spring Cloud applications, Eureka integration is often convenient in one environment and unnecessary in another. Selectively disabling the Eureka client usually means choosing whether you want to disable registration, disable registry fetching, or disable the whole discovery client stack for specific profiles or deployments.

Decide What You Actually Want to Disable

There are three slightly different goals:

  • Stop the app from registering itself with Eureka.
  • Stop the app from fetching the registry.
  • Disable discovery client behavior entirely.

Those are not all the same thing. An application may still fetch the registry while not registering itself, or it may skip both.

Use Profile-Specific Configuration

The cleanest approach is usually profile-based configuration. For example, keep Eureka enabled in production but disable it locally.

application.yml:

yaml
spring:
  application:
    name: my-service

application-local.yml:

yaml
eureka:
  client:
    enabled: false

Then run the app with the local profile active. This keeps the change externalized and avoids hard-coding discovery rules in Java code.

Disable Only Registration or Fetching

Sometimes you do not want a full shutdown of the client. You may only want to stop registration or stop consuming registry updates.

Examples:

yaml
1eureka:
2  client:
3    register-with-eureka: false
4    fetch-registry: false

That pair is a useful option when a service should neither publish itself nor resolve others through Eureka in that environment.

If you disable only registration:

yaml
eureka:
  client:
    register-with-eureka: false

then the service can still use Eureka to discover other services.

Consider the Broader Discovery Switch

In some Spring Cloud setups, a broader discovery toggle may also be appropriate:

yaml
1spring:
2  cloud:
3    discovery:
4      enabled: false

That switch affects discovery-client behavior more generally, not just Eureka-specific settings. Use it when the whole discovery abstraction should be inactive.

If the rest of the application depends directly on DiscoveryClient, disabling discovery at this level is often clearer than tuning only Eureka-specific flags.

Prefer Configuration Over Conditional Code

You can make discovery-related beans conditional in Java, but configuration properties are usually the better first choice. They are easier to test across environments and easier for operations teams to reason about.

Java-side conditionals become more useful when custom discovery beans or side effects need to exist only in certain profiles.

Example Conditional Bean

If you do need profile-based Java wiring, keep it explicit:

java
1import org.springframework.context.annotation.Bean;
2import org.springframework.context.annotation.Configuration;
3import org.springframework.context.annotation.Profile;
4
5@Configuration
6public class ClientConfig {
7
8    @Bean
9    @Profile("!local")
10    public MyDiscoveryAwareComponent myDiscoveryAwareComponent() {
11        return new MyDiscoveryAwareComponent();
12    }
13}

That does not disable Eureka by itself, but it shows how to keep discovery-dependent components out of selected environments.

Common Pitfalls

The most common mistake is disabling registration but forgetting that the app still tries to fetch the registry. If the real goal is “no Eureka traffic at all,” disable both or disable the discovery client entirely.

Another issue is mixing profile files and environment variables without knowing which one wins. If a property seems ignored, check the effective configuration order.

People also forget that other parts of the app may still depend on discovery abstractions. Turning off Eureka can expose hidden assumptions in load balancing or service lookup code.

Finally, do not hard-code environment-specific discovery rules in Java if a property or profile can express the same intent more cleanly.

Summary

  • Decide whether you need to disable registration, registry fetching, or all discovery behavior.
  • Profile-specific configuration is usually the cleanest way to do it.
  • 'eureka.client.enabled=false disables the Eureka client for that environment.'
  • 'register-with-eureka and fetch-registry let you disable only specific behaviors.'
  • Check the rest of the application for hidden dependencies on service discovery before switching it off.

Course illustration
Course illustration

All Rights Reserved.