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