做外贸的网站域名怎么买,天津百度爱采购,哪个网站教人做美食,西宁站 网站Eureka介绍与基本使用 一个简单的Eureka服务器的设置方法#xff1a;1 在pom.xml中添加Eureka服务器依赖#xff1a;2 在application.properties或application.yml中添加Eureka服务器配置#xff1a;3 创建启动类#xff0c;使用EnableEurekaServer注解启用Eureka服务器1 在pom.xml中添加Eureka服务器依赖2 在application.properties或application.yml中添加Eureka服务器配置3 创建启动类使用EnableEurekaServer注解启用Eureka服务器 一个Eureka客户端的设置方法1 在pom.xml中添加Eureka客户端依赖2 在application.properties或application.yml中添加Eureka客户端配置3 在启动类上使用EnableDiscoveryClient注解来启用服务发现 Eureka是Netflix开发的服务发现框架本身是一个基于REST的服务主要用于定位运行在AWS域中的中间层服务以达到负载均衡和中间层服务故障转移的目的。 SpringCloud将它集成在其子项目spring-cloud-netflix中以实现SpringCloud的服务发现功能。 Eureka是Netflix开发的一个用于实现服务注册和发现的服务。Spring Cloud集成了Eureka使我们可以非常方便地将Eureka集成到Spring Cloud的微服务架构中。
一个简单的Eureka服务器的设置方法
1 在pom.xml中添加Eureka服务器依赖
dependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-eureka-server/artifactId/dependency
/dependencies2 在application.properties或application.yml中添加Eureka服务器配置
server:port: eureka:instance:hostname: localhostclient:registerWithEureka: falsefetchRegistry: falseserviceUrl:defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/3 创建启动类使用EnableEurekaServer注解启用Eureka服务器
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;EnableEurekaServer
SpringBootApplication
public class EurekaServerApplication {public static void main(String[] args) {SpringApplication.run(EurekaServerApplication.class, args);}
}启动Eureka服务器后就可以在http://localhost:8761/上看到Eureka的管理页面。
对于Eureka客户端通常是指那些将自身服务注册到Eureka服务器并从Eureka服务器获取其他服务信息的客户端。这通常是指微服务架构中的各个服务。
一个Eureka客户端的设置方法
1 在pom.xml中添加Eureka客户端依赖
dependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-eureka-client/artifactId/dependency
/dependencies2 在application.properties或application.yml中添加Eureka客户端配置
eureka:client:serviceUrl:defaultZone: http://localhost:8761/eureka/instance:preferIpAddress: true3 在启动类上使用EnableDiscoveryClient注解来启用服务发现
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;EnableDiscoveryClient
SpringBootApplication
public class ClientApplication {public static void main(String[] args) {SpringApplication.run(ClientApplication.class, args);}
}启动Eureka客户端后它会自动将自己注册到Eureka服务器其他服务则可以通过Eureka服务器来发现和调用该客户端的服务。