当前位置:   article > 正文

搭建eureka-server_怎么新建eurakaserver

怎么新建eurakaserver

首先要搭建注册中心服务端:eureka-server,这必须是一个独立的微服务

1.创建项目

        创建maven工程即可

2.引入依赖

提示:starter是springboot中的自动装配,在这个依赖里,已经帮我们把eureka的所有配置都做好了

  1. <dependencies>
  2. <!--
  3. eureka服务端
  4. 不需要写版本信息,因为在父工程中已经把这些依赖的版本都管理好了
  5. -->
  6. <dependency>
  7. <groupId>org.springframework.cloud</groupId>
  8. <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
  9. </dependency>
  10. </dependencies>

3.编写启动类

        这种自动装配是需要开关的,故需要添加@EnableEurekaServer注解

  1. package cn.itcast.eureka;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
  5. /**
  6. * @author 温柔哥
  7. * @create 2024-01-16 20:33
  8. */
  9. @EnableEurekaServer // 自动装配的开关
  10. @SpringBootApplication
  11. public class EurekaApplication {
  12. public static void main(String[] args) {
  13. SpringApplication.run(EurekaApplication.class, args);
  14. }
  15. }

4.编写配置

        添加application.yml文件

  1. server:
  2. port: 10086 # 服务端口,随便起
  3. # --------------服务注册---------------
  4. # 因为eureka-server也是一个微服务,所以也需要注册
  5. spring:
  6. application:
  7. name: eurekaserver #eureka的服务名称
  8. eureka:
  9. client:
  10. service-url: # eureka的地址信息(这是用来eureka集群内他们相互交流配置的)
  11. defaultZone: http://127.0.0.1:10086/eureka # 如果有多个的话,用逗号分隔开

5.启动验证

        访问成功

Eurekaicon-default.png?t=N7T8http://localhost:10086/

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/天景科技苑/article/detail/974649
推荐阅读
相关标签
  

闽ICP备14008679号