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.
To disable the Eureka Discovery Client, you can set eureka. client. enabled to false . Eureka Discovery Client will also be disabled when spring.
The @EnableEurekaClient annotation makes your Spring Boot application act as a Eureka client. To register the Spring Boot application into Eureka Server we need to add the following configuration in our application. properties file or application. yml file and specify the Eureka Server URL in our configuration.
There is no difference.
application. eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/
You can disable eureka client in application.yml using this:
eureka:
client:
enabled: false
It's also for one profile
Do it like this: create some @Configuration
annotated class (class body can be omitted) ex.:
@Profile("!development")
@Configuration
@EnableDiscoveryClient
public class EurekaClientConfiguration {
}
It means that this configuration file (and @EnableDiscoveryClient
within) will be loaded in every profile except "developement".
Hope that helps,
With the latest version of Spring Cloud Finchley.SR2 if you are using the annotation @EnableDiscoveryClient you have to set all of the following properties in application.properties to disable the service registration:
spring.cloud.service-registry.auto-registration.enabled=false
eureka.client.enabled=false
eureka.client.serviceUrl.registerWithEureka=false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With