在Eureka中:
- Eureka Server
作为注册中心提供服务注册和发现
- Service Provider
- Service Consumer
案例实践
创建Maven父工程
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
f在父工程下创建一个 Module,实现 Eureka Server。
在 pom.xml 中添加 Eureka Server 依赖。
<dependency>
<groupid>org.springframework.cloud</groupid>
<artifactid>spring-cloud-starter-netflix-eureka-server</artifactid>
</dependency>
z在resources 路径下创建配置文件 application.yml,添加 Eureka Server 相关配置。server:
port: 8761
eureka:
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://localhost:8761/eureka/
属性说明:- server.port:当前 Eureka Server 服务端口。
- eureka.client.register-with-eureka:是否将当前 Eureka Server 服务作为客户端进行注册。
- eureka.client.fetch-registry:是否获取其他 Eureka Server 服务的数据。
- eureka.client.service-url.defaultZone:注册中心的访问地址。
@SpringBootApplication
@EnableEurekaServer
public class RegisterCenterApplication {
public static void main(String[] args) {
SpringApplication.run(RegisterCenterApplication.class,args);
}
}
注解@SpringBootApplication:声明该类是 Spring Boot 服务的入口。
注解@EnableEurekaServer:声明该类是一个 Eureka Server 微服务,提供发现服务的功能,即注册中心。
运行 RegistryCenter,启动成功控制台输出如下信息。
打开浏览器,访问 http://localhost:8761,可看到如下界面,注册中心启动成功。
No instances avaliable 表示当前没有发现微服务实例,即没有微服务完成注册,如果我们将 application.yml 中的 register-with-eureka 属性值改为 true,如下所示,则表示 Eureka Server 将自己作为客户端进行注册。
重启 RegisterCenterApplication ,打开浏览器访问 http://localhost:8761,可看到如下界面,当前注册中心有一个客户端服务UNKNOWN注册在案,即 Eureka Server 自己。
可以给注册中心一个名称,修改application.yml,添加配置信息:
server:
port: 8761
eureka:
client:
register-with-eureka: true
fetch-registry: false
service-url:
defaultZone: http://localhost:8761/eureka/
spring:
application:
name: center
重启 RegisterCenterApplication ,打开浏览器访问 http://localhost:8761,可看到如下界面,center就是注册中心的名称了。自此就完成了Spring Cloud注册中心Eureka Server的搭建。









Mgm casino slot machines at Mahaganatapati Temple - JTM Hub
ReplyDeleteThe Mgm 인천광역 출장샵 casino slot machine at Mahaganatapati Temple, Mahaganatapati Temple is 광명 출장마사지 located in the city 삼척 출장안마 Mahaganatapati Temple of Maharashtra. 양산 출장안마 Rating: 5 · 부산광역 출장안마 5 reviews