ITPub博客

首页 > IT职业 > IT图书 > Spring Cloud构建微服务架构—创建“服务注册中心”

Spring Cloud构建微服务架构—创建“服务注册中心”

IT图书 作者:zzzhangyi 时间:2021-09-09 09:21:54 0 删除 编辑

创建一个基础的Spring Boot工程,命名为eureka-server,并在pom.xml中引入需要的依赖内容:

org.springframework.boot

spring-boot-starter-parent

1.5.4.RELEASE

org.springframework.cloud

spring-cloud-starter-eureka-server

org.springframework.cloud

spring-cloud-dependencies

Dalston.SR1

pom

import

通过@EnableEurekaServer注解启动一个服务注册中心提供给其他应用进行对话。这一步非常的简单,只需要在一个普通的Spring Boot应用中添加这个注解就能开启此功能,比如下面的例子:

@EnableEurekaServer

@SpringBootApplication

public class Application {

public static void main(String[] args) {

new SpringApplicationBuilder(Application.class)

.web(true).run(args);

}

}

在默认设置下,该服务注册中心也会将自己作为客户端来尝试注册它自己,所以我们需要禁用它的客户端注册行为,只需要在application.properties配置文件中增加如下信息:

spring.application.name=eureka-server

server.port=1001

eureka.instance.hostname=localhost

eureka.client.register-with-eureka=false

eureka.client.fetch-registry=false

为了与后续要进行注册的服务区分,这里将服务注册中心的端口通过server.port属性设置为1001。启动工程后,可以看到下面的页面,其中还没有发现任何服务。

图片描述

从现在开始,我这边会将近期研发的springcloud微服务云架构的搭建过程和精髓记录下来,帮助更多有兴趣研发spring cloud框架的朋友,希望可以帮助更多的好学者。大家来一起探讨spring cloud架构的搭建过程及如何运用于企业项目。


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3598/viewspace-2802695/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-14

  • 博文量
    133
  • 访问量
    947