有没有办法根据弹簧配置文件禁用spring-boot eureka客户端注册?
目前我使用以下注释:
@Configuration
@EnableAutoConfiguration
@EnableDiscoveryClient
@EnableConfigServer
public class ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}
我需要的是一个条件如(借用伪代码)
@if (Profile!="development")
@EnableDiscoveryClient
@endif
或者在应用程序属性文件中的某种方式。我已经尝试将application.yml文件设置为:
spring:
profiles: development
cloud:
discovery:
enabled: false
但这没效果。
这样做:创建一些@Configuration
注释类(类体可以省略)ex。:
@Profile("!development")
@Configuration
@EnableDiscoveryClient
public class EurekaClientConfiguration {
}
这意味着除了“developpement”之外,每个配置文件中都会加载此配置文件(以及@EnableDiscoveryClient
)。
希望有所帮助,
您可以使用以下命令禁用application.yml中的eureka客户端:
eureka:
client:
enabled: false
它也适用于一个档案
同样的问题在这里您只需在应用程序属性文件中输入以下配置:
spring:
profiles: development
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
有一个标准的布尔spring-cloud属性
spring.cloud.discovery.enabled
这可能比“eureka”更具体,因为您可能正在使用其他提供程序。
使用最新版本的Spring Cloud Finchley.SR2如果使用注释@EnableDiscoveryClient,则必须在application.properties中设置以下所有属性以禁用服务注册:
spring.cloud.service-registry.auto-registration.enabled=false
eureka.client.enabled=false
eureka.client.serviceUrl.registerWithEureka=false
使用最新版本的Spring启动,请在bootstrap.yml文件中添加
Spring云版:Edgeware:SR3及以上版本
spring:
application:
name: test
cloud:
service-registry:
auto-registration:
enabled: false
这将禁用尤里卡。要启用它,我们只需要启用为true